Keeping HDD files in virtual memory without changing paths to files
I suppose my question is very specific, but I hope there might be solution already.
I want to make few folders available in virtual memory but not changing the way they are accessed like virtualization tool that will copy files in virtual memory and redirects IO operation to those files to virtual memory.
I have huge source folders that are often recompiled by maven, and I want to increase overall build speed by making those sources available in ram instead of hdd.
I'm familiar with ImDisk but I cant break environment by changing paths to sources (there are lot of tools already configured).
So the question is : is there any solution for above described problem?
Regards
Possible solution
Assuming that:
- you already created a RAM drive in physical memory assigned to
R:
(any other letter is fine too). - you want to make the folder
C:\Folder1
available in RAM for faster access. -
Folder1
is stored on a local NTFS formatted volume.
Applying the changes
- Close all programs that might be accessing
Folder1
. - Rename
Folder1
toFolder1.zTarget
(the actual name is not important as long as it's different). - Copy
Folder1.zTarget
to RAM drive (R:
). - Create a directory junction link named
Folder1
pointing toR:\Folder1.zTarget
.
From now on, every time you access C:\Folder1
what you're actually accessing is the data stored on the RAM drive (R:\Folder1.zTarget
).
Reverting back
- Close all programs that might be accessing
Folder1
(now a directory junction link). - If any file inside
Folder1
was modified, copy theFolder1.zTarget
from RAM (R:
) to disk (C:
) to preserve the changes. - Delete the directory junction link named
Folder1
. - Rename
Folder1.zTarget
back toFolder1
.
Batch automation
Even though most of the steps can be performed manually, there's no built-in way to create directory junctions links but from the command line interface (mklink
). While we're at it, we can save time by automating the whole process.
Example script
After a brief initialization, the script will check if there are any folders whose name contains the custom suffix. It will then proceed either applying or reverting the changes for each folder set in the folders
variable, just as described above - except for the "close all programs" steps.
@echo off
set folders="C:\Folder1","C:\Some other\folder"
set suffix=zTarget
set ramdisk=R:
for %%G in (%folders%) do (
dir "%%~dpG" /a:d | find ".%suffix%" >nul
goto :check
)
:check
if "%errorlevel%"=="0" goto :revert
:apply
for %%G in (%folders%) do (
if exist "%%~G\" (
ren "%%~G" "%%~nG.%suffix%"
xcopy "%%~G.%suffix%" "%ramdisk%%%~pnG.%suffix%" /e /i /f /h /r /k /y /j
mklink /j "%%~G" "%ramdisk%%%~pnG.%suffix%"
echo.
))
goto :end
:revert
for %%G in (%folders%) do (
if exist "%%~G.%suffix%\" (
xcopy "%ramdisk%%%~pnG.%suffix%" "%%~G.%suffix%" /e /i /f /h /r /k /y /j
rd "%%~G"
ren "%%~G.%suffix%" "%%~nG"
echo.
))
:end
pause
exit /b