我在为目标设置路径变量时遇到问题,我想将 forfiles 命令中的文件复制到 ( cmd /c copy @path destination
)。编码:
REM source folder location
set source=\\Path\TO\File\SOURCE\FOLDER
REM destination folder location
set set destination=E:\LOCAL\FOLDER\
REM log_file location
set log_file=E:\LOCAL\FOLDER\Logfile.txt
SET /a "copy_count+=0"
PUSHD %source%
for /F "delims=" %%F in ('
forfiles /S /D -2 /C "cmd /c copy @path 0x22%destination%0x22 & echo @file %date%, %time%>>0x22%log_file%0x22"
') do SET /a "copy_count"+=1
POPD
无法复制指定目录中的文件,但将路径直接传递到命令中,例如:
.....
for /F "delims=" %%F in ('
forfiles /S /D -2 /C "cmd /c copy @path E:\LOCAL\FOLDER\ & echo @file %date%, %time%>>0x22%log_file%0x22"
') do SET /a "copy_count"+=1
POPD
作品。
我需要如何正确传递变量?
在@Compo发表评论后编辑为工作代码
REM source folder location
set "source=\\Path\TO\File\SOURCE\FOLDER"
REM destination folder location
set "destination=E:\LOCAL\FOLDER\"
REM log_file location
set "log_file=E:\LOCAL\FOLDER\Logfile.txt"
SET /a "copy_count+=0"
PUSHD %source%
for /F "delims=" %%F in ('
forfiles /S /D -2 /C "cmd /c If @IsDir==FALSE copy @path %destination% & echo @file %date%, %time%>>%log_file%"
') do SET /a "copy_count"+=1
POPD
澄清@aschipfl评论,因为我没有意识到时间戳在整个过程中保持不变 - 这是您的评论所暗示的吗?
SET /a "copy_count+=0"
PUSHD %source%
(for /F "delims=" %%F in ('
forfiles /S /D -2 /C "cmd /c If @IsDir==FALSE copy @path %destination% & echo @file %date%, %time%)>>%log_file%"
') do SET /a "copy_count"+=1
POPD