-1

There is a huge amount of pdf files in my datacenter's subdirectories. In a local folder i want to check if the existing files are already in the datacenter's dir and if yes to move them to another local folder. I want to filter my search to .pdf files that have been modified today, otherwise the whole search thing in datacenter's subdirs takes ages.

@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

What should i add to above for command ?

Roy J.
  • 1
  • 1
  • Please try to explain the task better, it's much easier to help with code when we're satisfied that we know what it is supposed to do. _You can do that by [editing your question](https://stackoverflow.com/posts/52130460/edit), to include that information, and preferably including an example of the directory tree being worked on._ – Compo Sep 01 '18 at 17:18
  • Take a look at `help robocopy`. `MAXAGE` or `MAXLAD`, combined with `/MOV` may be exactly what you need. – jwdonahue Sep 01 '18 at 18:08
  • `/MIR` might actually be more appropriate for you needs, if what you really want to do is only copy files over that are missing in the target folder. No loops required by the way. – jwdonahue Sep 01 '18 at 18:27
  • i want a comparison between files in F1 and \\server\pdf subdirs and if the files in F1 exist there, they must be moved from F1 to F3 locally. I don't think your suggestions fit in here if i am not completely mistaken. – Roy J. Sep 01 '18 at 21:00

1 Answers1

0

You already know about the ForFiles command, mentioning it in your duplicate question on DosTips; so why not use it?

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)

If you prefer you could use Move with the /Y option or you could forget about the If Exist and just supress error messages, but the general idea should work for you.

Compo
  • 36,585
  • 5
  • 27
  • 39