How to Copy Files from Multiple Sub-folders 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 which explains how to move all files recursively from multiple sub-folders 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

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

Move or Copy Files in Sub-folders 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

Libraries feature was first introduced in Windows 7, and it 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:

D:\PHOTOS
└───Camera
    ├───2018-01
    ├───2018-02
    ├───2018-04
    ├───2018-05
    └───2018-07

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

    That’s it! the files in the Camera folder are copied/moved recursively to the destination — the empty sub-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 queryWe’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 simply 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 and 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 files in the 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 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 Make New Folder button and assign 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 Total Commander

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

  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. Alternately, you can enable Branch View (With Subdirs) via the Commands menu. 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 of the window. 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 “Temporary” attributes is set for a file. So, it’s prudent to make sure 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 are 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 camera, but the procedure to move or copy all files from multiple sub-folders to a separate folder (a.k.a “flattening a directory structure”) is the same for all other situations.

About the author

Ramesh Srinivasan founded Winhelponline.com back in 2005. He is passionate about Microsoft technologies and he has been a Microsoft Most Valuable Professional (MVP) for 10 consecutive years from 2003 to 2012.

4 thoughts on “How to Copy Files from Multiple Sub-folders 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.

Leave a Comment