我想弄清楚为什么这段代码不起作用。我创造了类似的东西工作正常,但这不起作用,不知道为什么。有谁知道为什么?
@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%a-%%b-%%c)
For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a-%%b)
xcopy %ThisService_RootDirectory%"saves\*.*" %ThisService_RootDirectory%"backups\worlds\%mydate%_%mytime%" /E /I /Y
答案 0 :(得分:0)
您的引号在XCopy
命令中关闭,它们位于路径中间而不是开头和结尾。
将其更新为:
REM Create the directory.
MKDIR "%ThisService_RootDirectory%backups\worlds\%mydate%_%mytime%"
REM Copy the files.
xcopy "%ThisService_RootDirectory%saves\*.*" "%ThisService_RootDirectory%backups\worlds\%mydate%_%mytime%" /E /I /Y
您的变量%ThisService_RootDirectory%
应该不在相应的SET
语句中引用,因为您要向其附加子目录。
例如:
REM Set this way [quotes around then entire declaration].
SET "ThisService_RootDirectory=C:\path\to\user\8\"
REM Do NOT set this way [quotes around just the path].
SET ThisService_RootDirectory="C:\path\to\user\8\"