Reputation: 2362
I have a directory structures like so:
C:\mydir\foo\a.zip
C:\mydir\foo\b.zip
C:\mydir\bar\c.zip
C:\mydir\baz\d.zip
I would like to move all files in C:\mydir\*\*.zip to C:\mydir so the output structure would be:
C:\mydir\a.zip
C:\mydir\b.zip
C:\mydir\c.zip
C:\mydir\d.zip
...with the superfluous empty folders potentially still present. How do I accomplish this using only the DOS command-line?
Upvotes: 1
Views: 4487
Reputation: 12871
Try this:
CD /D C:\mydir
FOR /f "delims=" %a IN ('DIR *.zip /s /b') DO MOVE "%a" .
It first changes the directory to C:\mydir
. The DIR
lists all zip-files in subdirectories with filenames only. The FOR
makes sure each lines goes into the variable %a
. MOVE
basically moves each file found into the current directory, i.e. C:\mydir
.
Upvotes: 4