Beerlol
Beerlol

Reputation: 357

Alternative to multiple robocopy commands iterating the same directory

I have a list of file extensions I need to collect all the files of from a particular directory while maintaining attributes, timestamps etc. which has resulted in my usage of Robocopy. I'm hoping someone can suggest a more efficient method than my current solution?

At present I copy these files using the following command into an "unprocessed" directory:

robocopy %Directory1% "%Directory2%\unprocessed" /Z /E /copy:dat *.pst *.ost *.doc *.docx *.pdf *.docm *.xls *.xlsx *.ppt /log+:%Directory%.txt

The individual collected files from inside the "unprocessed" directory are then sorted to individual folders named after each file extension and created at the same level as the "unprocessed" directory, again using individual Robocopy commands:

robocopy "%directory2%\unprocessed" %directory2%\pst *.pst /Z /E
...
...
robocopy "%directory2%\unprocessed" %directory2%\ppt *ppt /Z /E

As you can appreciate, this results in unnecessary iterations of the "unprocessed" directory multiple times. I'm unable to copy files straight to the final resting places due to the nature of robocopy so I'm hoping someone can suggest a more suitable solution that will still allow file attributes to remain intact.

(I apologise in advance that this could turn into a discussion as opposed to someone being directly able to answer this)

Upvotes: 2

Views: 815

Answers (1)

Scott C
Scott C

Reputation: 1660

Given the % signs in your examples, it looks like you're probably running this as part of a batch file. Either way, if you have the environment variables defined, you could use the following:

Command line:

for %e in (pst ost doc docx pdf dcom xls xlsx ppt) do robocopy "%Directory1%" "%Directory2%\%e" /Z /E /copy:dat *.%e /log+:%Directory%.txt

Bat file:

for %%e in (pst ost doc docx pdf dcom xls xlsx ppt) do robocopy "%Directory1%" "%Directory2%\%%e" /Z /E /copy:dat *.%%e /log+:%Directory%.txt

One other thing to note: You'll probably end up with all docx files in both doc and docx, likewise xlsx would end up in both xls and xlsx. Windows always picks up longer extensions with 3 character extensions.

Upvotes: 1

Related Questions