我想为我的办公室制作一个自动备份脚本。我做了一些研究,最后得到了一些灯泡,但问题是我的代码只能在Windows 7中运行,并且不能在Windows 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
感谢
答案 0 :(得分:1)
这应该是可靠的,以完成相同的任务。
您确定需要xcopy中的/d
开关吗?
@echo off
:loop
echo waiting... Please insert the flash drive...
ping -n 3 "" >nul
set "drv="
for %%a in (g h i j) do if exist "%%a:\" set "drv=%%a:"
if not defined drv goto :loop
REM drv IS THE FLASH DRIVE.
set start.hour=%time:~0,2%
set start.min=%time:~3,2%
set "d8=%date:~7,2%-%date:~4,2%-%date:~10,4%"
xcopy "%drv%\*.*" /s /c /d /e /h /r /y "%userprofile%\desktop\a\%d8%\"
set end.hour=%time:~0,2%
set end.min=%time:~3,2%
pause
我相信你的总时间计算被打破了,这是你可以解决的问题。