Solved DOS Batch/Robocopy Experts - Can this be streamlined?

September 12, 2012 at 12:25:56
Specs: Windows XP
I've created this to read a group of folders, sub-folders and files from one UNC path and append/copy it to another.

Is there a way to clean this up, incorporating Delayed Expansion and local variables instead of external files?

It also copied empty folders from the Source. Can they be filtered out?

If exist c:\LogFile1.log del c:\LogFile1.log
If exist c:\LogFile2.log del c:\LogFile2.log
dir "%Source%\59-*" /a:d /b >folders.tmp
for /f "usebackq delims=," %%I in (folders.tmp) do dir "%Source%\%%I" /a:d /b /s >>folders1.tmp
for /f "delims=@" %%I in (folders.tmp) do @echo %%I >>folders.txt
for /f "tokens=6* delims=\" %%A in (folders1.tmp) do @echo %%A\%%B >>folders.txt
for /f "usebackq delims=@ tokens=*" %%A in (folders.txt) do robocopy "%Source%\%%A" "%Target1%\%%A" /CREATE /S /XF *.bak *.drf *.fix *.htm *.log *.rsc *.s01 *.xls *.xlsx *.avi *.db *.zip *.msg *.tmp *.err *.txt *.doc *.docx *.ppt *.tif /R:5 /W:5 rem /LOG+:c:\LogFile1.log
for /f "usebackq delims=, tokens=*" %%A in (folders.txt) do robocopy "%Source%\%%A" "%Target1%\%%~nxA" /S /XF *.bak *.drf *.fix *.htm *.log *.rsc *.s01 *.xls *.xlsx *.avi *.db *.zip *.msg *.tmp *.err *.txt *.doc *.docx *.ppt *.tif /R:5 /W:5 /LOG+:c:\LogFile1.log
del c:\folders.txt c:\folders1.tmp c:\folders.tmp 

See More: DOS Batch/Robocopy Experts - Can this be streamlined?

Report •

September 12, 2012 at 20:03:57
@echo off & setlocal
set excludes=*.bak *.drf *.fix *.htm *.log *.rsc *.s01 *.xls *.xlsx *.avi *.db *.zip *.msg *.tmp *.err *.txt *.doc *.docx *.ppt *.tif
set otheropts=/R:5 /W:5 /LOG+:c:\LogFile1.log
:: main loop
for /f %%a in ('dir /a:d /b %source%\59-*') do (
robocopy /e "%source%\%%a" "%target%\%%a" /xf %excludes% %otheropts%
:: end
not sure, never used the robo before. It will prob'ly need some tweaking/debugging.

Report •

September 13, 2012 at 10:25:56
✔ Best Answer
Unless I'm missing something:
del c:\LogFile1.log c:\LogFile2.log 2>NUL
for /d %%A in ("%Source%\59-*") do robocopy "%%A" "%Target1%\%%~nxA" /S /XF *.bak *.drf *.fix *.htm *.log *.rsc *.s01 *.xls *.xlsx *.avi *.db *.zip *.msg *.tmp *.err *.txt *.doc *.docx *.ppt *.tif /R:5 /W:5 /LOG+:c:\LogFile1.log

How To Ask Questions The Smart Way

Report •

Related Solutions

Ask Question