我对批处理文件中的for循环感到头疼。
基本上,我通过存档文件夹进行搜索,以查看文件是否已被处理。如果是,则将文件移动到duplicates文件夹。我在脚本中设置了上面的日期变量,它们工作正常:
for %%f in (%toLoadLocation%\*.*) DO (
if exist %archiveLocation%\%%~nxf (
IF NOT EXIST "%archiveLocation%\Duplicates" mkdir "%archiveLocation%\Duplicates"
IF NOT EXIST "%archiveLocation%\Duplicates\%localYYYY%" mkdir "%archiveLocation%\Duplicates\%localYYYY%"
IF NOT EXIST "%archiveLocation%\Duplicates\%localYYYY%\%localMM%" mkdir "%archiveLocation%\Duplicates\%localYYYY%\%localMM%"
copy %%f "%archiveLocation%\Duplicates\%localYYYY%\%localMM%"
echo %localDate% %localTime% Duplicate claims file: %%f File moved to archive >> "%logLocation%\Error.log"
)
我在这里做些蠢事吗?我没有收到错误,脚本只是在运行时弹出这个(我之前和之后都有一个暂停命令,希望能收到一条消息,但什么都没有)
非常感谢任何帮助。
谢谢你们!
答案 0 :(得分:1)
试试这个:
for %%f in ("%toLoadLocation%\*.*") DO if exist "%archiveLocation%\%%~nxf" (
IF NOT EXIST "%archiveLocation%\Duplicates" mkdir "%archiveLocation%\Duplicates"
IF NOT EXIST "%archiveLocation%\Duplicates\%localYYYY%" mkdir "%archiveLocation%\Duplicates\%localYYYY%"
IF NOT EXIST "%archiveLocation%\Duplicates\%localYYYY%\%localMM%" mkdir "%archiveLocation%\Duplicates\%localYYYY%\%localMM%"
copy "%%~f" "%archiveLocation%\Duplicates\%localYYYY%\%localMM%"
echo %localDate% %localTime% Duplicate claims file: %%f File moved to archive >> "%logLocation%\Error.log"
)
答案 1 :(得分:0)
你应该在这两行上使用引号:
if exist "%archiveLocation%\%%~nxf" (
和
copy "%%f" "%archiveLocation%\Duplicates\%localYYYY%\%localMM%"