您好我有以下脚本将创建一个带有日期戳的文件夹,并尝试将文件从源文件复制到目标文件并排除文件夹
我直接尝试使用它的工作路径,但是当我使用的变量从未工作时
任何想法
@echo off
set "sourcePath = C:\temp\"
set "destinationPath = C:"
set "exlude =test2"
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "datestamp=%YYYY%%MM%%DD%"
if not exist "%destinationPath%\%datestamp%" mkdir %destinationPath%\%datestamp%
robocopy %sourcePath% %destinationPath%\%datestamp% /mir /XD %sourcePath%%exlude%
答案 0 :(得分:2)
删除变量声明中的空格。别担心,这让每个人都感到高兴。
@echo off
set "sourcePath=C:\temp\"
set "destinationPath=C:"
set "exlude=test2"
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "datestamp=%YYYY%%MM%%DD%"
if not exist "%destinationPath%\%datestamp%" mkdir %destinationPath%\%datestamp%
robocopy %sourcePath% %destinationPath%\%datestamp% /mir /XD %sourcePath%%exlude%