Advertisement
Guest User

FOR, ROBOCOPY and nested FOR commands

a guest
May 14th, 2025
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. @echo OFF
  2. title Free Utility for Cloning Saves
  3.  
  4. set script_path=%~dp0
  5. set backup_folder=%script_path%
  6. set overwrite_toggle=0
  7. set robocopy_options=/e /tee /log:robocopy.log
  8. set settings_path=%USERPROFILE%\AppData\Local\FUCS
  9. set masterlist_path=%settings_path%\masterlist.txt
  10. set open_when_finished=0
  11.  
  12. :initialize
  13. if exist "%settings_path%" (
  14. if exist "%settings_path%\settings.txt" (
  15. (
  16. set /p backup_folder=
  17. set /p overwrite_toggle=
  18. set /p robocopy_options=
  19. set /p open_when_finished=
  20. )<"%settings_path%\settings.txt"
  21. goto :main
  22. ) else (
  23. goto :setup
  24. )
  25. ) else (
  26. mkdir "%settings_path%"
  27. goto :setup
  28. )
  29.  
  30. :setup
  31. cls
  32. echo.
  33. echo Free Utility for Cloning Saves requires a folder to store data.
  34. echo You may set one now:
  35. set /p backup_folder="> "
  36. echo Is this correct?: %backup_folder%
  37. set /p ch="Y/N "
  38. if /i "%ch%" == "Y" goto :save_data
  39. if /i "%ch%" == "N" goto :setup
  40. goto :setup
  41.  
  42. :save_data
  43. (
  44. echo %backup_folder%
  45. echo %overwrite_toggle%
  46. echo %robocopy_options%
  47. echo %open_when_finished%
  48. )>"%settings_path%\settings.txt"
  49. goto :main
  50.  
  51. :main
  52. cls
  53. echo.
  54. echo [1 / ADD ENTRIES TO MASTERLIST ]
  55. echo [2 / REMOVE ENTRIES FROM MASTERLIST]
  56. echo [3 / VIEW MASTERLIST ]
  57. echo [E / PERFORM BACKUP ]
  58. echo [S / SETTINGS ]
  59. echo [Q / QUIT ]
  60. set /p ch="> "
  61. if /i "%ch%" == "1" goto :masterlist_add_entry
  62. if /i "%ch%" == "2" goto :masterlist_remove_entry
  63. if /i "%ch%" == "3" goto :masterlist_view
  64. if /i "%ch%" == "E" goto :backup_masterlist_check
  65. if /i "%ch%" == "S" goto :change_settings
  66. if /i "%ch%" == "Q" goto :eof
  67. goto :main
  68.  
  69. :backup_masterlist_check
  70. if exist "%masterlist_path%" (
  71. set masterlist_size=0
  72. for %%a in ("%masterlist_path%") do if %%~za equ 0 (
  73. echo Warning: The masterlist.txt file contains no entries.
  74. pause & goto :main
  75. ) else (
  76. goto :backup_begin
  77. )
  78. ) else (
  79. echo Warning: FUCS could not find the masterlist file.
  80. echo Attempting to add an entry should create the file if it does not exist.
  81. pause & goto :main
  82. )
  83.  
  84. :backup_begin
  85. rem Whichever entry in masterlist.txt is last will overwrite any previous created folders.
  86. for /f "tokens=*" %%i in (%masterlist_path%) do (
  87. for /f "tokens=*" %%g in (%masterlist_path%) do robocopy %%g %backup_folder%\%date%\%%~nxi /MIR
  88. )
  89. rem original method - does not create individual folders
  90. rem for /f "tokens=*" %%g in (%masterlist_path%) do robocopy %%g %backup_folder%\%date% %robocopy_options%
  91. echo Robocopy has finished the operation. Read robocopy.log for more details.
  92. pause & goto :main
  93.  
  94. :masterlist_add_entry
  95. cls
  96. echo.
  97. echo Specify the path to the folder you wish to backup.
  98. set /p ch="Path to folder: "
  99. echo %ch% >> "%masterlist_path%"
  100. echo %ch% has been added to the masterlist.
  101. pause & goto :main
  102.  
  103. :masterlist_remove_entry
  104. cls
  105. echo.
  106. echo Specify the path to the folder you wish to remove from the masterlist.
  107. SET /P ch="Path to the folder: "
  108. echo %ch% has been removed from the masterlist.
  109. type %masterlist_path% | findstr /v "%ch%" >"%settings_path%\~temp.txt"
  110. del %masterlist_path% && ren "%settings_path%\~temp.txt" masterlist.txt
  111. goto :main
  112.  
  113. :masterlist_view
  114. cls
  115. echo Current masterlist entries:
  116. echo.
  117. for /f "tokens=*" %%g in (%masterlist_path%) do echo %%g
  118. echo [Q / QUIT ]
  119. set /p ch="> "
  120. if /i "%ch%" == "Q" goto :main
  121.  
  122. :change_settings
  123. cls
  124. echo.
  125. echo Change or view settings.
  126. echo.
  127. echo Backup Folder: %backup_folder%
  128. echo Open When Finished?: %open_when_finished% ^| 1=True 0=False
  129. echo Overwrite Toggle: %overwrite_toggle% ^| 1=True 0=False
  130. echo [1 / TOGGLE OVERWRITE SWITCH ]
  131. echo [2 / CHANGE BACKUP FOLDER ]
  132. echo [3 / TOGGLE OPEN WHEN FINISHED ]
  133. echo [Q / QUIT ]
  134. set /p ch="> "
  135. if /i "%ch%" == "1" goto :toggle_overwrite_switch
  136. if /i "%ch%" == "2" goto :backup_folder_change
  137. if /i "%ch%" == "3" goto :toggle_open_when_finished
  138. if /i "%ch%" == "Q" goto :main
  139. goto :change_settings
  140.  
  141. :toggle_overwrite_switch
  142. if %overwrite_toggle% equ 0 (
  143. set robocopy_options=/e /is /it /tee /log:robocopy.log
  144. set overwrite_toggle=1
  145. goto :save_data
  146. ) else (
  147. set robocopy_options=/e /tee /log:robocopy.log
  148. set overwrite_toggle=0
  149. goto :save_data
  150. )
  151.  
  152. :backup_folder_change
  153. cls
  154. echo.
  155. echo Enter the path to a new folder to store backups:
  156. set /p backup_folder="> "
  157. echo Is this correct?: %backup_folder%
  158. set /p ch="Y/N "
  159. if /i "%ch%" == "Y" goto :save_data
  160. if /i "%ch%" == "N" goto :main
  161. GOTO :SETTINGS
  162.  
  163. :toggle_open_when_finished
  164. if %open_when_finished% equ 1 (
  165. set open_when_finished=0
  166. goto :save_data
  167. ) else (
  168. set open_when_finished=1
  169. goto :save_data
  170. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement