Advertisement
PinothyJ

Create RAM Disk (imDisk Required)

Apr 11th, 2014
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. set endcmd=echo.
  3. ::End cmd is a one line command that runs after this script. Do nothing 'echo.' is default.
  4. set steam=
  5. set launch=
  6. set redun=
  7. set link=
  8. set startin=
  9. set drive=
  10. set sum=
  11. set target=
  12. set value=
  13. set confirm=
  14. set CD=
  15. set removebat=
  16. set remove=
  17. setLocal EnableDelayedExpansion
  18. set verbose=0
  19. ::0=no
  20. ::1=verbose output
  21. set replace=0
  22. ::0=unspecified
  23. ::1=overwrite without prompt
  24. ::2=skip/ignore without prompt
  25. set param=0
  26. ::0=no parameters passed
  27. ::1=parameters passed to batch
  28. set quiet=0
  29. ::0=quiet mode off
  30. ::1=quiet mode active
  31. :start
  32. IF NOT "%1" == "" GOTO %1
  33. IF %param% == 1 GOTO skiptxt
  34. echo This batch file will create a virtual drive in your RAM and automatically copy
  35. echo (not move) a folder in the current directory onto aforementioned virtual
  36. echo drive. A junction will automaticall be created so you can use this batch file
  37. echo with Origin or Steam without any hassels.
  38. echo.
  39. echo Please do not include quotation marks in the filename or thousands separators
  40. echo in the integers. The easiest way to use this batch file is to copy it into the
  41. echo directory of the folder you wish to mount, F2 the folder as if you were going
  42. echo to rename it and copy the folder name as it appears. To paste in the command
  43. echo window you will have to right-click and select 'paste' from the context menu
  44. echo that appears.
  45. echo.
  46. :skiptxt
  47. IF NOT "%startin%" == "" (
  48.     %startin:~,1%:
  49.     cd "%startin%"
  50. )
  51. IF "%link%" == "" set /p link= Folder Name (in current directory):
  52. IF "%remove%" == "" set remove=%link%
  53. echo.
  54. IF %param% == 0 set /p drive= Drive Letter (Leave blank for default (R:)):
  55. IF "%drive%" == "" set drive=R
  56. :driveloopreturn
  57. call :strlen result drive
  58. IF EXIST "%drive%:" ( GOTO driveloop ) ELSE IF NOT %result% == 1 ( GOTO driveloop )
  59. set target=%drive%:\%link%
  60. IF %param% == 0 set /p sum= Set Ramdisk size in KiB (blank for automatic detection):
  61. IF "%redun%" == "" set /a redun=5
  62. IF "%sum%" == "" IF %param% == 0 set /p redun= Set Redundancy (extra space) between 1-99 (sans percentage sign, default 5):
  63. set /a redun=!redun!+100
  64. IF "%sum%" == "" GOTO extractsize
  65. :extractreturn
  66. GOTO writebat
  67. :writereturn
  68. GOTO mount
  69. :mountreturn
  70. MD "%target%"
  71.  
  72. echo.
  73. echo Moving content to RAM Disk…
  74. robocopy "%link%" "%target%" /E /COPY:DAT /XJ /R:0 /W:0 >nul
  75. IF errorlevel 8 set sum=
  76. set /a redun=!redun!-99
  77.  
  78. move "%link%" "%link%ORIGINAL"
  79. mklink /j "%link%" "%target%"
  80. echo.
  81. echo.
  82. IF "%sum%" == "" GOTO quietskip
  83.  
  84. IF %verbose% == 1 (
  85.     echo.
  86.     echo.
  87.     echo Redundancy value = !redun! %%
  88.     echo Size = !sum! KiB
  89.     echo Drive = %drive%
  90.     echo Link = %link%
  91.     echo Target = %target%
  92.     echo Starting Directory = %startin%
  93.     echo Launch = %launch%
  94.     echo Steam Link = %steam%
  95.     echo Quiet = %quiet%
  96.     echo Replace = %replace%
  97.     echo.
  98.     echo.
  99. )
  100.  
  101. IF NOT "%launch%" == "" start "Launching…" /WAIT "%link%\%launch%"
  102. IF NOT "%steam%" == "" start "Launching…" /WAIT "%steam%"
  103. IF NOT "%launch%%steam%" == "" GOTO dismount
  104. goto exit
  105. :extractsize
  106. set /a value=0
  107. FOR /R "%link%" %%I IN (*) DO (
  108. set /a value=%%~zI/1024
  109. set /a sum=!sum!+!value!
  110. )
  111. set /a sum=!sum!/100
  112. set /a sum=!sum!*!redun!
  113. GOTO extractreturn
  114. :dismount
  115. echo Close this window if you do not wish to proceed with mount removal and/or copy.
  116. echo.
  117. IF NOT "%steam%" == "" pause
  118. IF "%steam%" == "" IF %quiet% == 0 pause
  119. IF %replace% == 1 GOTO replaceloopend
  120. IF %replace% == 2 GOTO replaceskip
  121. :replaceloopstart
  122. set /p confirm= Overwrite folder on HDD with RAMDisk content? (Y or N):
  123. IF /I "%confirm%" == "N" GOTO replaceskip
  124. IF /I "%confirm%" == "Y" GOTO replaceloopend
  125. GOTO replaceloopstart
  126. :replaceloopend
  127. set replace=1
  128. rmdir "%link%"
  129. robocopy "%drive%:" "%CD%" /E /COPY:DAT /XJ
  130. :replaceskip
  131. echo.
  132. IF %quiet% == 1 GOTO quietskip
  133. echo Are you sure you want to remove the mount and return back to normal operation?
  134. pause
  135. :quietskip
  136. imdisk -D -m %drive%:
  137. rmdir "%link%"
  138. IF NOT %replace% == 1 move "%link%ORIGINAL" "%link%"
  139. IF %replace% == 1 RD /S "%link%ORIGINAL"
  140. del %removebat%
  141. IF "%sum%" == "" GOTO skiptxt
  142. GOTO exit
  143. :driveloop
  144. IF %quiet%%param% == 00 (set /p drive= Drive Letter in use or not valid, try again ^(type 'quit' to close this window^): ) ELSE GOTO exit
  145. IF "%drive%" == "quit" GOTO :eof
  146. GOTO driveloopreturn
  147. :strlen <resultVar> <stringVar>
  148. (
  149.     set "s=!%~2!#"
  150.     set "len=0"
  151.     for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
  152.         if "!s:~%%P,1!" NEQ "" (
  153.             set /a "len+=%%P"
  154.             set "s=!s:~%%P!"
  155.         )
  156.     )
  157. )
  158. (
  159.     set "%~1=%len%"
  160.     exit /b
  161. )
  162. :writebat
  163. set removebat="remove%remove%.bat"
  164. echo @echo off>>%removebat%
  165. echo echo If you press a key the virtual drive in your RAM will be deleted. >>%removebat%
  166. echo echo Close this window if you do not wish to proceed.>>%removebat%
  167. echo echo.>>%removebat%
  168. IF %quiet% == 0 echo pause>>%removebat%
  169. IF NOT "%launch%%steam%" == "" (
  170. echo echo.>>%removebat%
  171. echo echo Are you sure you want to remove the mount and return back to normal operation?>>%removebat%
  172. IF %quiet% == 0 echo pause >>%removebat%
  173. echo.
  174. )
  175. echo imdisk -D -m %drive%:>>%removebat%
  176. echo rmdir "%link%">>%removebat%
  177. echo move "%link%ORIGINAL" "%link%">>%removebat%
  178. echo del %removebat%>>%removebat%
  179. GOTO writereturn
  180. :mount
  181. imdisk -a -s !sum!K -m %drive%: -p "/fs:ntfs /q /y"
  182. GOTO mountreturn
  183. :cycle2
  184. SHIFT
  185. :cycle1
  186. SHIFT
  187. set param=1
  188. GOTO start
  189. :-in
  190. :/in
  191. set startin=%~2
  192. GOTO cycle2
  193. :-f
  194. :/f
  195. set link=%~2
  196. GOTO cycle2
  197. :-d
  198. :/d
  199. set drive=%~2
  200. GOTO cycle2
  201. :-r
  202. :/r
  203. set /a redun=%~2
  204. GOTO cycle2
  205. :-s
  206. :/s
  207. set /a sum=%~2
  208. GOTO cycle2
  209. :-l
  210. :/l
  211. set launch=%~2
  212. GOTO cycle2
  213. :-st
  214. :/st
  215. set steam=%~2
  216. GOTO cycle2
  217. :-q
  218. :/q
  219. set quiet=1
  220. GOTO cycle1
  221. :-ow
  222. :/ow
  223. set replace=1
  224. GOTO cycle1
  225. :-iw
  226. :/iw
  227. set replace=2
  228. GOTO cycle1
  229. :-v
  230. :/v
  231. set verbose=1
  232. GOTO cycle1
  233. :-e
  234. :/e
  235. @echo on
  236. GOTO cycle1
  237. :-ec
  238. :/ec
  239. set endcmd=%~2
  240. set endcmd=%endcmd:""="%
  241. GOTO cycle2
  242. :exit
  243. IF %quiet% == 0 pause
  244. %endcmd%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement