批量搜索并移动特定类型的重复文件

时间:2018-09-01 17:09:59

标签: batch-file for-loop datemodified

我的数据中心的子目录中有大量的pdf文件。在本地文件夹中,我想检查现有文件是否已经在数据中心的目录中,如果是,则将其移动到另一个本地文件夹中。 我想将搜索结果过滤为今天已修改的.pdf文件,否则数据中心子目录中的整个搜索内容将花费一定的时间。

@echo off
pushD \\server\pdf
for /r %%i in ( *.pdf ) do (
if exist "%userprofile%\desktop\F1\%%~nxi" ( move /y "%userprofile%\desktop\F1\%%~nxi" %userprofile%\desktop\F3 
) else echo File %%~nxi is not a duplicate
)
popD
pause

我应该在上面添加什么命令?

1 个答案:

答案 0 :(得分:0)

您已经了解ForFiles命令,并在您对DosTips 的重复问题中提到了该命令;那为什么不使用它呢?

PushD "\\server\pdf" 2>Nul && (
    ForFiles /S /M *.pdf /D 0 /C "Cmd /C If Exist \"%UserProfile%\Desktop\F1\@File\" If Not Exist \"%UserProfile%\Desktop\F3\@File\" Move \"%UserProfile%\Desktop\F1\@File\" \"%UserProfile%\Desktop\F3\""
    PopD)

如果您愿意,可以将Move/Y选项一起使用,或者您可以忘记If Exist而忽略错误消息,但是一般的想法应该对您有用