How to Copy Files from Multiple Subfolders to a Single Folder?

When importing photos from your camera or SD card via AutoPlay dialog using the Photos app, many sub-folders (month and year-wise) are created in the destination folder, which may not be what you wanted. Here is a step-by-step guide that explains how to move all files recursively from multiple subfolders to a single folder of your choice.

For example, here is how it gets imported when using the Photos app.

move or copy files in multiple sub-folders

The mobile phones and cameras also may store your photos in many subfolders under the DCIM folder.

For instance, in Apple iPhone, your photos and videos are stored in the 100APPLE folder under DCIM. The 100APPLE folder contains IMG_0001.JPG to IMG_0999.JPG. If you have more images or videos, then they’re stored in 101APPLE , 102APPLE directory, and so forth. If you’re using iCloud to store photos and videos, you’ll also see the folders namely, 100CLOUD, 101CLOUD, and so on.

iphone dcim

Copying the files from each subfolder to a single folder on your hard disk manually can be a tiresome task, especially if you have a large number of folders. However, you don’t need to dig into every folder to do that, as there are several ways to quickly copy or move files from all the subfolders to a single folder — i.e., flatten a directory structure.

Move or Copy Files in Subfolders to a Single Folder

You can copy or move files from sub-folders to a single folder using at least three different built-in ways in Windows. This procedure is also known as flattening a directory structure. Follow one of the three methods, whichever one you find easy.

Method 1: Using Command-line

Scenario: Let’s copy all files from the d:\vacation snaps\2016 folder and sub-folders to the d:\all snaps folder recursively.

  1. Open a Command Prompt window.
  2. Run the following commands, one by one and press ENTER after each line:
    md "d:\all snaps"
    cd /d "d:\vacation snaps\2016"
    for /r %d in (*) do copy "%d" "d:\all snaps\"

    This recursively copies all files in the d:\vacation snaps\2016\ folder to the d:\all snaps\ folder. To move the files, replace copy with move

If a file of the same name exists in the destination, you’ll be asked if you want to overwrite or skip the file.

Note: It’s always safe to include the trailing backslash (\) after the destination folder path, as in the above example. Because, without the trailing slash, if the destination path is missing and you run the command, then the files in the folder and subfolders are copied and combined into one single file named all snaps to D:\ drive.

Method 2: Using the Libraries feature in Windows

The Libraries feature, first introduced in Windows 7, is also available in subsequent versions, including Windows 10. Libraries are virtual containers for users’ content. A library can contain files and folders stored on the local computer or in a remote storage location. Windows libraries are similar to “Saved Search” and are backed by full content search and rich metadata.

You can aggregate content from multiple storage locations into a single, unified view using Libraries. Let’s use the Libraries feature in Windows to flatten a directory structure.

Let’s say we have a folder structure like this:


Copy Files from Multiple Sub-folders to a Single Folder

Under each folder, we have several photos imported from the camera. To flatten the Camera directory structure and consolidate all images in a single folder, follow these steps:

  1. Open the top-most folder (i.e., Photos) whose structure you want to flatten.
  2. From the File menu, click Options. Click the View tab
    Move or Copy Files in Multiple Sub-Folders
  3. Enable Show hidden files, folders, and drives
  4. Uncheck Hide protected operating system files (Recommended)
  5. Click OK.
  6. Right-click on the parent directory (i.e., Camera in this example), and click Include in libraryCreate new library.Copy Files from Multiple Sub-folders to a Single Folder
    A new library is created with the same name as the folder.
  7. In the left pane of File Explorer, expand Libraries and select the newly created library.
  8. By default, the items in libraries are arranged by Folders. To have an aggregated view of files in that directory structure (and hide the folders), right-click an empty area in the library and click Arrange byName
    Copy Files from Multiple Sub-folders to a Single Folder
  9. Select the Home tab.
  10. Click Select all in the ribbon, or press Ctrl + A to select all the files in the library view.
  11. Click on the Move To or the Copy To button, as per your requirement.
  12. Select the destination folder to copy/move the files to, and click Move (or Copy)
    Copy Files from Multiple Sub-folders to a Single Folder
    Copy Files from Multiple Sub-folders to a Single Folder
    The files in the Camera folder and its subfolders are now copied/moved to the destination; the folders remain.Copy Files from Multiple Sub-folders to a Single Folder
  13. Delete the Camera library if you no longer need it.

Next, we’ll see how to accomplish the same using Windows Search in Method 3 below.

Method 3: Using Windows Search

Using Windows Search is another easy way to flatten a directory structure if you don’t prefer the command-line.

  1. Open the parent folder (the top-level folder), which contains many sub-folders.
    move or copy files in multiple sub-folders
  2. From the File menu, click Options. Click the View tab
    Move or Copy Files in Multiple Sub-Folders
  3. Enable Show hidden files, folders, and drives
  4. Uncheck Hide protected operating system files (Recommended)
  5. Click OK.
  6. In the Search box, type the following search query, exactly as below:
    *.* NOT type:"file folder"

    A note about the above search query:

    We’re using the NOT operator to prevent Windows search from listing the file-system folders (directories) — as we’re only going to copy or move the files and not the folders themselves.
    • The search query *.* NOT "file folder" works only on indexed locations. If your source folder location is not indexed, then use *.*

    Yes. You can use *.* (which will list folders in search results). If so, when you reach Step 8, you’ll need to select all files leaving out the folders shown.

    move or copy files in multiple sub-folders

  7. With the All subfolders search option enabled by default, Windows Search starts searching for all matching items in all sub-folders, recursively. It lists all matching files, including those with System or Hidden (or both) attributes.
  8. Wait until the search is completed, and then select all search results by pressing Ctrl + A.
  9. Select the Home tab.
  10. In the Home tab, click on the Copy To button. To move the files instead of copying, click the Move to button instead. Click the Choose location… option in the Move To dropdown menu.move or copy files in multiple sub-folders
  11. In the Move Items dialog, select the folder where you want to move all the files. To create a new folder, click the Make New Folder button and give the folder name accordingly. Once selected the folder, click Move. This moves all the files recursively from the multiple sub-folders to the destination folder chosen.move or copy files in multiple sub-folders

Method 4: Using 7-Zip

7-Zip is not just a compression utility, but it also has file management capabilities that can be useful for other purposes. 7-Zip supports the “Flat View” feature that can help us quickly locate files in multiple subfolders, or copy them to a different location.

  1. Launch 7-Zip and browse the parent folder.
  2. From the View menu, enable Flat View.
    7-zip flat view
  3. Select all the files, leaving out the folders.
    7-zip flat view
  4. Right-click on the selection and select Copy To…
  5. Mention the target folder path, and click OK.

That’s it. The selected files are copied to the selected folder (flattened.)

Note that you can also enable the “2 Panels” view via 7-Zip’s View menu and copy the files by dragging to the desired folder in the right pane. You must make sure to press the Ctrl key while dragging. Or else, the files will be moved to the target location instead. Pressing the  Ctrl key ensures the drag operation is “copy.

Method 4: Using Total Commander

If you’re using the Total Commander file manager software, you can flatten a directory structure easily.

  1. Launch Total Commander and open the folder that you want to flatten.
    total commander flatten a directory
  2. Press Ctrl + B to change the mode to Branch view. Alternatively, you can enable Branch View (With Subdirs) via the Commands menu. The Branch View is a view mode where files from the folder and subfolders (recursively) are listed, and the folders are not displayed.
    total commander flatten a directory
  3. Select all files in the list, and click the Copy button (F5) at the bottom. To move the files, click the Move button (F6).
  4. Select the target directory, uncheck Keep relative paths and click OK.
    total commander flatten a directory

That’s it. This copies or moves all the files in the source directory tree to the target folder (flattened).

Making sure every file has been moved successfully

Important: Windows Search may not list every file in search results in some cases, either due to indexing issues or if the “Temporary” attribute is set for a file. It’s prudent to ensure that there are no files left behind at the source location, before clearing out those folders.

RELATED: Windows Search Not Finding Google Drive Files and Folders

To verify that, right-click the parent folder (or select all sub-folders and right-click) in the source location, and click Properties. If you had moved the items instead of copying, the Properties tab should say “0 Files“. That means every file has been successfully moved to the new location.

move or copy files in multiple sub-folders

Alternately, you can check the Properties tab in the destination path and make sure the number of files is the same (total 33 files, as seen in the image under Step #6 above).

move or copy files in multiple sub-folders

Once you ensure every file has been moved, the folders in the old location can be deleted.

This post takes the case of photos imported from a camera. But the procedure to move or copy all files from multiple sub-folders to a separate folder (aka “flattening a directory structure”) is the same for all other situations.

One small request: If you liked this post, please share this?

One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:
  • Pin it!
  • Share it to your favorite blog + Facebook, Reddit
  • Tweet it!
So thank you so much for your support. It won't take more than 10 seconds of your time. The share buttons are right below. :)

Ramesh Srinivasan is passionate about Microsoft technologies and he has been a consecutive ten-time recipient of the Microsoft Most Valuable Professional award in the Windows Shell/Desktop Experience category, from 2003 to 2012. He loves to troubleshoot and write about Windows. Ramesh founded in 2005.

31 thoughts on “How to Copy Files from Multiple Subfolders to a Single Folder?”

  1. Thank you so much. You saved so much time of mine. I was coping my music list, folder by folder and pasting the content into one folder.

  2. How can i run this in a batch file?
    Because the following code is not working when I put it in batch file and execute.

    md “d:\all snaps”
    cd /d “d:\vacation snaps\2016”
    for /r %d in (*) do copy “%d” “d:\all snaps\”

  3. I wanted to just copy the (*.wma)s from multiple directories under a main directory, which had other files, into one directory for simple sharing. This was perfect! Thank you for saving me time now and in the future!

    example: open Command prompt and type
    cd /d “/path/to/originating-folder”
    for /r %d in (*.wma) do copy “%d” “/path/to/destination-folder”

  4. @MP Ramkumar (and anyone else, like me, who had this question:)

    In a batch file, use %% where you use % from the command line:

    for /r %%d in (*) do copy “%%d” “d:\all snaps\”

  5. Thank you so very much for all the time and careful thinking you put into this. This is the 6th place I looked and was by far the best.

  6. Use the windows search. Select all the folders and search in the file extensions of the photos i.e. *.jpg or *.png and when it comes up with all the files listed with those extensions in those folders, select all of them, cut and paste into another folder. Do this once with all the file extensions – jpg, png, mov, whatever until those folders are empty. This, I’ve found, is the easiest and quickest way to do it, and then when all the folders are empty, just delete the empty folders.

  7. This was invaluable and “Total Commander” shareware was my preferred-visual/GUI method that avoided having to code. Now finally 10 years of scattered pics on multiple harddrives in one location (centralised and backup-able); now time to use DigiKam and organise those memories…Thanks a million 🙂

  8. How can one reverse this? I forgot to go into the main folder and was up one level. Now I have files I have no idea where they came from. LOL. So I cancelled the command prompt window to stop it from continuing but I can’t figure out where the files came from.

    • I can’t edit my question… I changed ‘copy’ to ‘move’ and thus my problem. I think I figured out where the files came from but before I move them, there’s no magical command to undo the move right?

    • @ColtonYYZ: I think the Windows shell offers you the “Undo move” command (in the folder background context menu) if you access it immediately after the wrong move operation.

  9. thanks a lot for great help.
    It will be great if Over right all you can give with the last copy command for this line “for /r %d in (*) do copy “%d” “d:\all snaps\”

    actual same name file command is asking again and again for over right


Leave a Comment