0

我对批处理文件中的这个 for 循环感到头疼。

基本上,我正在搜索存档文件夹以查看文件是否已被处理。如果是这样,则将文件移动到重复文件夹。我已经在脚本中设置了上面的日期变量,它们工作正常:

 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"
 )

我在这里做一些愚蠢的事情吗?我没有收到错误,脚本在运行时会爆炸(我在此之前和之后都有一个暂停命令,希望能捕捉到一条消息,但什么也没有)

任何帮助将非常感激。

多谢你们!

4

2 回答 2

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"
)
于 2013-08-05T21:02:32.747 回答
0

您应该在这 2 行中使用引号:

if exist "%archiveLocation%\%%~nxf" (

copy "%%f" "%archiveLocation%\Duplicates\%localYYYY%\%localMM%"
于 2013-08-05T20:51:50.130 回答