JSI Tip 3935. How do I copy all the files in a directory tree to a flat folder?

Jerold Schulman

July 25, 2001

1 Min Read
ITPro Today logo in a gray background | ITPro Today


If you wish to copy all the files in a directory and its' sub-directories to different directory, without preserving the directory structure:

CopyFlat From To

where From is the full path to the source directory and To is the full path to the target directory.

CopyFlat.bat contains:

@echo offsetlocalIf {%1} EQU {} goto SyntaxIf {%2} EQU {} goto Syntaxset from=%1set to=%2set from=%from:"=%#set to=%to:"=%#set from=%from:#=%set to=%to:#=%set from=%from:#=%set to=%to:#=%if not exist "%from%" goto Syntaxif not exist "%to%" goto Syntaxpushd "%to%"for /f "Tokens=*" %%i in ('dir /b /s /a-d "%from%*.*"') do call :cpy "%%i"popdendlocalgoto :EOF:Syntax@echo Syntax: CopyFlat From Toendlocalgoto :EOF:cpycopy %1 "%~nx1"



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like