Batchfile Help.

n72.75

Seize the means of computation
Orbiter Contributor
Addon Developer
Tutorial Publisher
Donator
Joined
Mar 21, 2008
Messages
2,872
Reaction score
1,714
Points
128
Location
Saco, ME
Website
mwhume.space
Preferred Pronouns
he/him
I have about 20000 folders in a directory each folder containing one file all with the same file extension.

I was wondering if anyone had any particular insight into how to write a batch file to copy all those files into one directory?

As an added bonus, its on a Windows machine.
 
Have a look at robocopy. it should be possible to do something like

robocopy c:\sourcedir\*.ext c:\destination /s

/s=scan subdirectories.

I don't have robocopy in front of me but it'll certainly do the trick.
 
Alternatively, installing the GnuWin32 tools to have "cp" at home should be helpful.

I think the command was:

cp -R root_dir/*.ext source_dir

(Important: capital -R not -r. The second copies the subdirectories as well.)
 
Last edited:
There's no need for any external programs.

Execute this command:
Code:
for /F "delims=" %i in ('dir /b /s *.ext') do copy /b "%i" "C:\Destination directory\"
Where ext is your file extension of files that need to be copied, and dir command is placed in single quotes/apostrophes. When called from inside the batch file instead of command line, the %i variable should be called %%i.
 
Back
Top