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 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.

Thanks.

share|improve this question
add comment

1 Answer

up vote 1 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
add comment

Your Answer

 
discard

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.