Productivity Tip: Copy Files From Subfolders to One Folder

So, you want to become more productive? How about learning how to copy files from subfolders to one specific folder. This could possibly be a huge time-saver! Let’s get to it.

How to copy files from subfolders

Using The Command Prompt To Copy Files – Simplified

Windows 7 provides several great tools that allow you to copy files more effectively. Unfortunately, most of them are only accessible via the command prompt. There are for example: copy, xcopy and robocopy. All three can be used to become more productive.

1. Step Open a command prompt
2. Step Enter cd C:\pathtoyourfolder **replace pathtoyourfolder with your actual path, e.g. C:\Users\username\Pictures

The Actual Code

3. Step Copy files from subfolders to one folder:
for /f "tokens=*" %a in ('dir /b /s /a-d') do @copy "%a" "C:\YourFolder" /y

Code Explanation

What is does is to look into each subfolder (dir /b /s /a-d) in the current folder and then copy each file in the subfolder. It will copy each file to the folder C:\YourFolder

What is the /y doing? I am using this option to NOT get prompted for overwriting files. If you don’t add /y it will always ask if you want to overwrite files with the same name. So, if you have files in the subfolders with the same name you will have to rename them first.

If you’ve done everything correctly, it will then copy all files within the subfolders and copy them to the folder that you specified:

Copy files from subfolders

Next up, are some more productivity tips, so stay tuned for more!

5 of 5 0 (100%) 1 vote
- Cheers!


Written by:
Oliver is the founder and lead editor of this site. He is interested in finding new ways to break Windows, find common errors and help others to fix them. Aside from that, he loves to fully customize systems with Rainmeter and Dreamscene, find out more about ancient civilizations like the Chachapoya, sharpen his digital photography skills and create software with a small group of selected developers. If you would like to connect with him to discuss anything, send him a mail!

Learn More About.Me

Follow me on Twitter for daily updates:

Contact The Author:

Get Free Help

Connect With Our Site:



Need help? Ask a question at our QA site, click the red button to get started:
Want to support us? Great, simply buy your favorite games from G2A via our referral link ( and save money at the same time:

7 Responses to Productivity Tip: Copy Files From Subfolders to One Folder

  1. Orange Community Approved Comment:
    Wilkie IT said:

    This does not work keep getting error *” was unexpected at this time.
    code was
    for /f “tokens=*” %a in (‘dir /b /s/a-d’) do @copy “%a” “d:\new\rar” /y

  2. Orange Community Approved Comment:
    Wilkie IT said:

    I have got this working. with the following

    for /f “tokens=*” %a in (‘dir /b /s /a-d “c:\test”‘) do @copy “%a” “d:\new\rar”

    It appears you left out the source folder (c:\test) in your example.

  3. Orange Community Approved Comment:
    raed said:

    working fine for me, many thanks
    any further detailes about win 7 cmd tools?

  4. Orange Community Approved Comment:
    rosy said:

    I kept getting the error:*” was unexpected at this time.

    Turns out if you just copy and paste the above, the quotes and double quotes come out wrong – you need to make sure that the quotes in the command prompt are straight up like this (” ‘) not slanted like this (“ ” ‘’)

  5. Orange Community Approved Comment:
    rosy said:

    …. aand they were autocorrected to the slanty ones in my comment above :(. basically, if you get the error, try manually typing the command out, not copy-paste.

  6. Orange Community Approved Comment:
    Dmitriy Krivelyov said:

    It works!
    But there are a few notes.

    The first is already described by Rosy – if you copied the source code from the browser, do not forget to replace quotes and double quotes.
    The second one is that if you put the commands in a batch file you must double the percents before the FOR variables. For example, %a on the command line would need to be %%a in a batch file.

  7. Orange Community Approved Comment:
    Dmitriy Krivelyov said:

    And one more useful note (all to be in one place :)).
    In case you need to copy all the files by some file name mask, you should use the following format:

    for /f “tokens=*” %%a in (‘dir “*.zip” /b /s /a-d’) do

    as you can see the file name mask is added right after the “dir” command.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current day month ye@r *