我已将此脚本(减去我的所有ECHO以提高您的可读性)将某些用户文件夹备份到外部设备。它运作完美,但我想知道是否有人对如何简化它有任何想法(例如,更“聪明”)。
我是这个网站的新手和编码。请耐心等待我!
所有帮助表示赞赏。
@ECHO OFF
SET driveLetter=%~d0
:CHOOSE
SET /P CHOOSE=Are you sure you want to continue [Y/N]?
IF /I "%CHOOSE%" == "Y" GOTO :chooseYes
IF /I "%CHOOSE%" == "N" GOTO :chooseNo
GOTO :CHOOSE
:chooseYes
MKDIR %driveLetter%\Desktop
MKDIR %driveLetter%\Documents
MKDIR %driveLetter%\Favorites
MKDIR %driveLetter%\Pictures
MKDIR %driveLetter%\Downloads
TIMEOUT /T 1 /NOBREAK >NUL
ROBOCOPY %USERPROFILE%\Desktop\ %driveLetter%\Desktop /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
ROBOCOPY %USERPROFILE%\Documents\ %driveLetter%\Documents /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
ROBOCOPY %USERPROFILE%\Favorites\ %driveLetter%\Favorites /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
ROBOCOPY %USERPROFILE%\Pictures\ %driveLetter%\Pictures /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
ROBOCOPY %USERPROFILE%\Downloads\ %driveLetter%\Downloads /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
CLEANMGR /C: /SAGERUN:65535 /SETUP
TIMEOUT /T 1 /NOBREAK >NUL
DEFRAG /C /H /V /W
PAUSE
EXIT
:chooseNo
TIMEOUT /T 3 /NOBREAK >NUL
最好的问候。
答案 0 :(得分:0)
如果可能,请不要重复
:chooseYes
for %%a in ( Desktop Documents Favorites Pictured Downloads ) do (
robocopy "%userprofile%\%%a" "%driveLetter%\%%a" /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
)
CLEANMGR /C: /SAGERUN:65535 /SETUP
TIMEOUT /T 1 /NOBREAK >NUL
DEFRAG /C /H /V /W
PAUSE
EXIT
注意:mkdir
已被抑制,因为robocopy
命令将创建目标文件夹