How do I copy all subdirectories?

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.

How do I copy all subdirectories?

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.

How do I copy all subdirectories?

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.

Flattening a directory structure

  1. Move or Copy Files in Sub-folders to a Single Folder
    • Method 1: Using Command Prompt
    • Method 2: Using the Libraries feature in Windows
    • Method 3: Using Windows Search
    • Method 4: Using the 7-Zip file manager
    • Method 5: Using Total Commander
  2. Making sure every file has been moved successfully

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:

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

How do I copy all subdirectories?

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
    How do I copy all subdirectories?
  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.
    How do I copy all subdirectories?

    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
    How do I copy all subdirectories?
  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)
    How do I copy all subdirectories?

    How do I copy all subdirectories?

    The files in the Camera folder and its subfolders are now copied/moved to the destination; the folders remain.
    How do I copy all subdirectories?
  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.


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.
    How do I copy all subdirectories?
  2. From the File menu, click Options. Click the View tab
    How do I copy all subdirectories?
  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.

    How do I copy all subdirectories?

  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.
    How do I copy all subdirectories?
  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.
    How do I copy all subdirectories?

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.
    How do I copy all subdirectories?
  3. Select all the files, leaving out the folders.
    How do I copy all subdirectories?
  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.
    How do I copy all subdirectories?
  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.
    How do I copy all subdirectories?
  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.
    How do I copy all subdirectories?

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.

How do I copy all subdirectories?

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

How do I copy all subdirectories?

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


How do I copy all subdirectories?

Which command would you use to copy all files and subdirectories?

To copy a directory with all subdirectories and files, use the cp command.

How do I copy a directory and subdirectories?

Copying Directories with cp Command If you want to copy directory, including all its files and subdirectories, use -R or -r option with cp command. The above command will create a destination directory and copy all files and subdirectories recursively to the /opt directory.

How do I copy a subdirectory?

To move folders and subfolders in cmd, the most used command syntax would be:.
xcopy [source] [destination] [options].
Click Start and type cmd in the search box. ... .
Now, when you're in the Command Prompt, you can type Xcopy command as below to copy folders and subfolders including contents. ... .
Xcopy C:\test D:\test /E /H /C /I..

How do I copy a directory and subdirectories in Linux?

In order to copy a directory on Linux, you have to execute the “cp” command with the “-R” option for recursive and specify the source and destination directories to be copied.