0
我想为我的办公室制作自动备份脚本。我已经做了一些研究并最终得到了一些灯泡,但问题是我的代码只能在Windows 7中运行,并且在Windows XP中无法运行。那么我如何解决这个问题?
这里是我的代码
批处理文件脚本在xp中不起作用
echo off
setlocal enabledelayedexpansion
:FIND.BACKUP.DRIVE.LETTER
set start.dir=%systemdrive%
J:
%cls%
if not "%cd:~0,2%"=="%start.dir%" goto next
I:
%cls%
if not "%cd:~0,2%"=="%start.dir%" goto next
H:
%cls%
if not "%cd:~0,2%"=="%start.dir%" goto next
G:
%cls%
if not "%cd:~0,2%"=="%start.dir%" goto next
if "%cd:~0,2%"=="%start.dir%" (
echo WAITING FOR FLASH MEDIUM TO BE CONNECTED . . .
if exist "%windir%\system32\timeout.exe" timeout /t 1 /nobreak >nul
if not exist "%windir%\system32\timeout.exe" pause
goto FIND.FLASH.DRIVE.LETTER
)
:next
set start.hour=%time:~0,2%
set start.min=%time:~3,2%
REM FLASH.DRIVE IS THE FLASH DRIVE.
set flash.drive=%cd:~0,2%
set date="%date:~7,2%-%date:~4,2%-%date:~10,4%"
mkdir "%userprofile%\desktop\a\%date%"
xcopy "%flash.drive%\*.*" /s /c /d /e /h /i /r /y %userprofile%\desktop\a\%date%
if not exist %flash.drive% set /a total.time=((((%time:~0,2%-%start.hour%)... && echo Flash Drive has been in for !total.time! minutes. && Pause>nul
@pause
感谢
1.“不会工作”的短语没有诊断价值:请编辑您的问题并指定出现了什么问题; 2.使用'echo ON'来查看究竟发生了什么; 3.对[_volatile_环境变量](http://ss64.com/nt/syntax-variables.html)不要使用'set date = ...'等:使用其他名称,例如'set _date = ...' – JosefZ
在批处理文件的顶部有一个标签'FIND.BACKUP.DRIVE.LETTER',但是做一个__goto__到'FIND.FLASH.DRIVE.LETTER',即'BACKUP'与'FLASH '。此外,我建议避免在标签和环境变量中使用驼峰,并使用CamelCase符号,即“FindFlashDriveLetter”和“StartDir”。还有在批处理代码中没有定义的环境变量'cls'的引用。不要使用'cls'作为变量名称以避免与命令__cls__混淆(清除屏幕)。替换'timeout'正在使用__ping__,请参阅[如何在批处理脚本中等待](http://stackoverflow.com/questions/735285/) – Mofi