Search This Blog

Monday, October 29, 2018

ROBOCOPY Returns to My Focus

I started out the day running this DOS Batch file that uses the more efficient "ROBOCOPY" command instead of the tested / verified / awesome "XCOPY" command. However, I quickly realized that the commands below were insufficient because each ROBOCOPY command was set up to copy the entire "S:\Disaster Recovery Planning" folder into each of the sub-folders within the c:\rh\drm folder structure, which is not what I want to do. What I want is:

to copy the CSV files within S:\Disaster Recovery Planning to the c:\rh\drm\csv folder
to copy the DOC* files within S:\Disaster Recovery Planning to the c:\rh\drm\DOC folder
repeating that logic for each of the file types I've specified in the commands below.

This is my original code:

cd\
c:
cd c:\rh\drm
rd /s /q c:\rh\drm\csv
rd /s /q c:\rh\drm\doc
rd /s /q c:\rh\drm\jpg
rd /s /q c:\rh\drm\png
rd /s /q c:\rh\drm\pdf
rd /s /q c:\rh\drm\ppt
rd /s /q c:\rh\drm\txt
rd /s /q c:\rh\drm\vsd
rd /s /q c:\rh\drm\xls
rd /s /q c:\rh\drm\zip
pause
md c:\rh\drm\csv
md c:\rh\drm\doc
md c:\rh\drm\jpg
md c:\rh\drm\png
md c:\rh\drm\pdf
md c:\rh\drm\ppt
md c:\rh\drm\txt
md c:\rh\drm\vsd
md c:\rh\drm\xls
md c:\rh\drm\zip
pause
robocopy "S:\Disaster Recovery Planning" c:\rh\drm\csv *.csv /E
pause
robocopy "S:\Disaster Recovery Planning" c:\rh\drm\doc *.doc* /E
pause
robocopy "S:\Disaster Recovery Planning" c:\rh\drm\jpg *.jpg /E
pause
robocopy "S:\Disaster Recovery Planning" c:\rh\drm\png *.png /E
pause
robocopy "S:\Disaster Recovery Planning" c:\rh\drm\pdf *.pdf /E
pause
robocopy "S:\Disaster Recovery Planning" c:\rh\drm\ppt *.ppt* /E
pause
robocopy "S:\Disaster Recovery Planning" c:\rh\drm\txt *.txt /E
pause
robocopy "S:\Disaster Recovery Planning" c:\rh\drm\vsd *.vsd* /E
pause
robocopy "S:\Disaster Recovery Planning" c:\rh\drm\xls *.xls* /E
pause
robocopy "S:\Disaster Recovery Planning" c:\rh\drm\zip *.zip /E
pause

I am very happy I had inserted "pause" commands so that I could check the progress in the destination folder because I quickly realized my syntax was wrong. Thanks to https://stackoverflow.com/questions/472692/how-to-copy-a-directory-structure-but-only-include-certain-files-using-windows, I know what I would need to do and, actually, I've improved upon the process. My original idea was to use a separate command to copy each file type to a folder for that file type, but now I realize, I can use a single command to copy the files to a single directory structure, use SearchMyFiles.exe to look for all the files in that single folder structure - instead of specifying each sub-folder - select all the files, cut, and paste into the root folder. Then I still use a second DOS Batch file to move each file type to a folder for that file type.

cd\
c:
cd c:\rh\drm
rd /s /q c:\rh\drm\csv
rd /s /q c:\rh\drm\doc
rd /s /q c:\rh\drm\jpg
rd /s /q c:\rh\drm\msg
rd /s /q c:\rh\drm\png
rd /s /q c:\rh\drm\pdf
rd /s /q c:\rh\drm\ppt
rd /s /q c:\rh\drm\txt
rd /s /q c:\rh\drm\vsd
rd /s /q c:\rh\drm\xls
rd /s /q c:\rh\drm\zip
pause
md c:\rh\drm\csv
md c:\rh\drm\doc
md c:\rh\drm\jpg
md c:\rh\drm\msg
md c:\rh\drm\png
md c:\rh\drm\pdf
md c:\rh\drm\ppt
md c:\rh\drm\txt
md c:\rh\drm\vsd
md c:\rh\drm\xls
md c:\rh\drm\zip
pause
robocopy "S:\Disaster Recovery Planning" c:\rh\drm\baggage *.csv *.doc* *.jpg *.msg *.png *.pdf *.ppt* *.txt *.vsd* *.xls *.zip /E

One command instead of 10 is always a cool thing!
It makes the requirements for using SearchMyFiles.exe easier as well. Here's the before:



See? Much more slick!

No comments: