How do I copy all the files in a folder and all of the files in its subfolders to a single folder on XP?


Assuming the names are all unique, you should be able to use this command (command group really):

for /f "tokens=*" %a in ('dir /b /s /a-d') do @copy "%a" "c:\Single-Folder"

To clarify - open a Command Prompt and in the root folder of the folder with the sub folders you want to copy, run that command. So, for example, if you want to copy everything in "C:\Sample Folder Tree" and all its sub directories, you could change into "C:\Sample Folder Tree" from the command prompt and then run that command.

Or, you could just specify it in the dir section like this:

for /f "tokens=*" %a in ('dir /b /s /a-d "c:\Sample Folder Tree"') do @copy "%a" "c:\Single-Folder"

If you want to see what this will do without it actually doing anything, add an "@echo" between the do and copy - like so:

for /f "tokens=*" %a in ('dir /b /s /a-d "c:\Sample Folder Tree"') do @echo copy "%a" "c:\Single-Folder"
| improve this answer | |
  • Or one could do for /r %a in ("C:\Path\To\Source\*") do @copy "%i" "C:\Path\To\Output" instead of for /f – afrazier May 4 '10 at 1:29
  • To copy all jpg files from F:\DCIM to directory D:\Projekte\egh\photo\00_Inbox\jpg, this worked on Windows 7: for /f "tokens=*" %%G in ('dir F:\DCIM*.jpg /b /s /a-d') DO copy %%G "D:\Projekte\egh\photo\00_Inbox\jpg" – Christian Schulzendorff Nov 20 '16 at 21:34
 robocopy c:/here c:/there/ /S /COPYALL

That works. It needs administration cmd unless you dont want /copyall (which copies permissions and i think timestamps instead of creating new timestamps).

theres a robocopy for XP and available on vista and Windows 7. copy works fine enough tho. I like robocopy bc it wont recopy the same files if the dest has a copy (lets say you get interrupted like a power outage or want to shutdown and sleep)

| improve this answer | |

You could use the disk cataloguing utility SuperCat.

| improve this answer | |

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