Posts Tagged ‘File Management’

Little Bit of DOS Magic

Tuesday, October 21st, 2008

Ok, so not really DOS, but rather the Windows XP interactive command console, whatever they’re calling it these days.  In any case, it comes in handy to perform tasks that a graphical interface just can’t handle efficiently.

I have a bunch of files categorized into multiple directories, like this:

2000 Aerials
— NJ
—- Burlington County
—— X00 to X03
—— X04 to X06
—- Camden County
—— etc.

I’d like to flatten the contents of all of the various subdirectories into one directory.  One ring to rule them all, one ring to find them, one ring to bring them all, and in the darkness bind them.

The for command is how to do it:

for /R . %f in (*.*) do copy /Y “%f” h:\destination

The /R switch tells for to run this command (the for command) in each directory under the listed director, which in this case is . (the current directory).  In each of the directories, for builds a list of all files matching *.*, and runs the copy command (substituting the %f with the filename).  Thus, wherever the for command recursively finds a file (and at whatever depth), that file is copied directly to the destination.