Mat Kelly
Mat Kelly

Reputation: 2362

Move nested files to root directory in DOS

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

Answers (1)

sjngm
sjngm

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

Related Questions