Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a folder (let's call it A) with lots of subfolders B, C, D, E, which then again have subfolders B1, B2, B3, ... C1, C2, C3 ...

How can I using cmd move all files from all subfolders into the "root" folder A?

share|improve this question
I am assuming you want every file in the one root, not in subfolders? So A\File1, A\File2, not A\Folder2\File1? –  Canadian Luke Oct 18 '11 at 19:45
@Luke - Yes, you got it. Every file that exists in folders and subfolders moved to root. –  ldigas Oct 18 '11 at 20:45

3 Answers 3

up vote 12 down vote accepted

My original post neglected to include the file's extension in the move command. %~ni only returns the basename, you need to use %~nxi to get both the filename and extension! I hope you haven't mangled your filenames on my account!(

From a Command Prompt:

cd /d C:\Path\To\A
for /r %i in (*) do @move "%i" "%~nxi"

If you need to cleanup the empty folders afterward:

for /d %i in (*) do @rd /s /q "%i"

Now, if you have any filename clashes, you're on your own. You can add the /y parameter to the move command (before the "%i") to force overwrites. If you want something different, you'll need another program that can auto-rename everything for you.

Also, if you want to use this in a batch file, change all the % to %%.

share|improve this answer
Didn't know about FOR /r -- nice! –  Daniel Beck Oct 18 '11 at 20:29
Wow, very awesome. I bow to your command-fu. –  Mokubai Oct 18 '11 at 21:23

Install Cygwin (or another Unix environment for Windows) and run the following:

cd A
find . -type f -exec mv {} . \;
share|improve this answer
Depending on your mv and find variants, you might need to use find . -type f -exec mv -t . {} \; instead. –  Daniel Beck Oct 18 '11 at 19:57
For native Windows ports of many Unix tools I like unxutils.sourceforge.net –  Dennis Oct 18 '11 at 19:58
@Dennis UnxUtils are nice, unfortunately quite old by now. If you're using them at the moment, could you verify my post works with them? mkdir -p a/a1 a/a2 a/a3 b/b1 b/b2 b/b3 c and touch a/a1/foo a/a1/bar a/a2/baz a/a3/qux b/b1/quux b/b2/quuux b/b3/quuuux c/ccc for preparation. –  Daniel Beck Oct 18 '11 at 20:08
-1 That may be true, but I was inquiring about how to do it in cmd. –  ldigas Oct 18 '11 at 20:43
@Daniel No doubt they are old, I have been dragging them around for years. I just tried find . -type f -exec mv {} . ; And it seemed to work ok. –  Dennis Oct 18 '11 at 20:44

Create a folder and copy all the other folders into it, then right click that folder and select Search. In the search box enter *.*.

This will list all the files and folders. Select all the files you want in your root directory and cut them. Navigate to your root directory and paste all the files there.

share|improve this answer
search doesn't exist as a command in my cmd. –  ldigas Nov 12 '12 at 15:12
Richard wasn't talking about a a command. Have edited his answer to make it clearer. –  Isaac Rabinovitch Nov 13 '12 at 4:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.