Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to copy all files in a folder and it's subfolders to a single folder, without copying the subfolders. From searching stackexchange, I've found this script:

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

while it does the job, it does not handle duplicates. You need to manually choose Yes/No. I need to be able to copy all files, either ignoring all duplicates or overwriting all duplicates (it does not matter, whatever is easiest).

I tried this:

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

adding the /Y but it then randomly skipped folders - so I think I added this argument in the wrong place.


share|improve this question
up vote 2 down vote accepted

Try this edited version of the first command

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

Which will automatically overwrite, or replace y with n to automatically not overwrite.

share|improve this answer

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.