我的.bat文件有什么问题?

时间:2015-07-02 15:31:36

标签: batch-file

我正在尝试xcopy一个包含所有子文件夹和文件的文件夹到另一个文件夹中,该文件夹被命名为当前日期和时间

这就是我所拥有的:

xcopy  C:\Users\t\Desktop\survival\world "C:\Users\t\Desktop\backups\survival\Backup-%date:/=/%_%time:~0,2%:%time:~3,2% /s /e /i
谁能帮助我吗? 感谢

1 个答案:

答案 0 :(得分:1)

%time:~0,2%:%time:~3,2%
           ^....You can not have a colon in a file name

此外,您错过了目标文件夹

末尾的结束语
@echo off
    setlocal enableextensions disabledelayedexpansion 

    set "source=C:\Users\t\Desktop\survival\world"
    set "target=C:\Users\t\Desktop\backups\survival\Backup"

:loop
    set "timeStamp=%date:/=/%_%time:~0,2%:%time:~3,2%"
    xcopy "%source%\." "%target%-%timeStamp%" /s /e /i
    ping -n 601 "" >nul 
    goto :loop