Skip to content

Instantly share code, notes, and snippets.

@bmatthewshea
Last active April 28, 2021 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmatthewshea/220f14fb0d421f1b1eaf5788d279e7be to your computer and use it in GitHub Desktop.
Save bmatthewshea/220f14fb0d421f1b1eaf5788d279e7be to your computer and use it in GitHub Desktop.
Copy/recurse folders/files using a text file. CMD / BATCH
@ECHO off
SET FileList=.\pathlist.txt
SET LOGGING=.\robocopy-copy-logs
REM EDIT THESE TWO PATHS BEFORE RUNNING (NO QUOTES! NO TRAILING BACKSLASH!)
SET Source-Path=E:\folders-under-this-root-need-copying
SET Dest-Path=D:\folder-under-which-to-place-copied-folders-from-E
REM ** XCOPY WORKS **
REM FOR /F "USEBACKQ TOKENS=*" %%F IN ("%FileList%") DO (XCOPY /Q /E /C /I "%Source-Path%\%%~F" "%Dest-Path%\%%~nxF\")
REM ** BUT, LETS USE ROBOCOPY AND SAVE A SEPERATE LOG FOR EACH FOLDER COPIED
FOR /F "USEBACKQ TOKENS=*" %%F IN ("%FileList%") DO (mkdir "%Dest-Path%\%%~nxF" & ROBOCOPY "%Source-Path%\%%~F" "%Dest-Path%\%%~nxF" /E /Z /ZB /R:2 /W:3 /V /MT:32 /log:%LOGGING%\robocopy-%%~nxF.log)
GOTO :EOF
@bmatthewshea
Copy link
Author

bmatthewshea commented Apr 28, 2021

"pathlist.txt" should just have the single top-level folder name to be found under your Source-Path.

If

 Source_Path = "D:\READMEs"
 Dest-Path   = "E:\PUBLISHED-READMEs"

And

pathlist.txt has:

 readmes-1
 readmes-2

Then it will copy the full path and files to:

 E:\PUBLISHED-READMEs\readmes-1\(and additional paths/files)
 E:\PUBLISHED-READMEs\readmes-2\(any additional paths/files) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment