Move Files From Subfolders to One Folder (Windows and Mac)
Move files from subfolders to one folder with File Explorer, PowerShell, Finder or Terminal, and deal with same-name files and leftover empty folders.
To move files from subfolders to one folder, search the main folder for every file, select the results and move them in one go. File Explorer and Finder both can, and one PowerShell or Terminal line does the same. What goes wrong is files with the same name and the empty folders left behind. This guide covers both.
The last method is for folders that keep refilling, such as a phone import that creates a new folder every day.
Before You Flatten a Folder: Three Decisions
Same names. Say you have D:\Photos\Export with 140 dated subfolders, from two cameras. Both cameras count from IMG_0001.jpg, so two files will want the same name in the destination. Decide whether to keep both with a number or skip the second one. Every method below behaves differently here.
Folder names carry information. An album, a client, a trip, a date: once files are piled together, that is gone. Put the folder name into the file name (File Arbor can, see Method 5) or keep the structure.
Where the files go. Either into the main folder itself or into a new folder. Moving inside one drive is instant. Across drives, files are copied and then deleted from the source, which takes longer. If the files matter and you are about to use a command, copy the whole folder first and flatten the copy.
5 Ways to Move Files Out of Subfolders, Compared
| Method | Works on | Same-name files | Empty subfolders afterwards | Undo | Repeats on its own |
|---|---|---|---|---|---|
| File Explorer search | Windows 10 and 11 | Explorer asks: replace, skip or compare and keep both | Left behind | Ctrl+Z right after | No |
| PowerShell | Windows 10 and 11 | The second file stays in its subfolder, with an error | Left behind | No | No |
| Finder search | macOS | Finder asks: keep both, stop or replace | Left behind | Edit → Undo right after | No |
| Terminal | macOS | The second file stays in its subfolder (mv -n) | Left behind | No | No |
| File Arbor (Pro) | Windows and Mac | Renamed with a number: IMG_0001 (1).jpg | Optional: to the Recycle Bin or Trash | Undo after the run, or per file in History | Yes, on a schedule |
None of the built-in methods removes the emptied subfolders. For those leftovers, see how to delete empty folders.
Method 1: Move All Files From Subfolders With File Explorer (Windows 11 and 10)
- Open the main folder, for example
D:\Photos\Export. - Click the search box at the top right, type
*and press Enter. Explorer searches this folder and every subfolder in it. - Switch to Details view and click the Type column, so the subfolders ("File folder") sort together, apart from the files.
- Click the first file, Shift-click the last file, and press Ctrl+X.
- Go to the destination, either the main folder itself or a new folder, and press Ctrl+V.
If a file with the same name is already there, Explorer asks whether to replace it, skip it or compare the two. In the compare window, tick both versions to keep both, and the moved file gets a number. Ctrl+Z straight after a move undoes it.
Explorer gets slow with tens of thousands of files. Hidden files only appear if hidden items are shown. And the emptied subfolders stay behind.
Method 2: Move Files From Subfolders to the Main Folder With PowerShell
Replace the path with your own, with no backslash at the end:
$root = "D:\Photos\Export"
Get-ChildItem -LiteralPath $root -File -Recurse |
Where-Object { $_.DirectoryName -ne $root } |
Move-Item -Destination $root
The command lists every file under the folder, skips the ones already in the main folder and moves the rest into it. To preview without moving anything, add -WhatIf at the end of the last line.
A file whose name already exists in the main folder is not overwritten. Move-Item refuses with "Cannot create a file when that file already exists", and the file stays in its subfolder. Rename it and run the command again. Hidden system files such as desktop.ini and Thumbs.db are left where they are. We tested this on Windows 11: a same-name file stayed in its subfolder with that error, and desktop.ini stayed put.
One warning. If you want to copy instead of move, do not swap Move-Item for Copy-Item. Copy-Item overwrites same-name files without asking. To keep the originals, copy the whole folder first and flatten the copy.
Method 3: Flatten a Folder on Mac With Finder Search
- Open the main folder in Finder and press Command-F.
- Next to "Search:", click the folder's name instead of "This Mac", so results come only from this folder and its subfolders.
- Set the criterion to Kind is Image, or PDF, Music, Movie, Document, whatever you are gathering. Choosing a kind keeps the folders themselves out of the results.
- Press Command-A, then Command-C.
- Open the destination folder and press Option-Command-V. That moves the items instead of copying them.
If a name is already taken, Finder asks whether to keep both, stop or replace. Keep both adds a number to the name. Edit → Undo straight after undoes the move.
Finder search relies on Spotlight, so folders it does not index return nothing; use Terminal for those. The emptied subfolders stay behind.
Method 4: Move Files From Subfolders With Terminal (Mac)
Change into the main folder, then run find:
cd ~/Pictures/Export
find . -mindepth 2 -type f ! -name .DS_Store -exec mv -n {} . \;
Here is what each part does:
-mindepth 2only picks files inside subfolders, so files already in the main folder stay put.- Excluding
.DS_Storeskips Finder's hidden view-settings files. mv -nnever overwrites, so a file whose name is already taken stays in its subfolder.
To preview, run the same line with -print in place of -exec mv -n {} . \;:
find . -mindepth 2 -type f ! -name .DS_Store -print
When the list looks right, run the real command, then remove the empty subfolders with the Terminal command in the empty folders guide.
Method 5: Flatten Folders Automatically With File Arbor
Methods 1 to 4 are for one-off flattening. When the folder keeps refilling with new subfolders (a camera import that makes a folder per day, course downloads, unzipped archives, a scanner that files by date), you would repeat the routine every week.
File Arbor does it on every run, handles same names, and can move the emptied folders to the Recycle Bin (new in 1.3.3). It is rule-based, with no AI, and everything runs locally. Subfolder scanning and Scheduled mode are Pro.
- Click Add Folder and choose the main folder, for example
D:\Photos\Exportor~/Pictures/Export. - Tick Scan subfolders on the folder card. It works in Single and Scheduled mode.
- Choose Pile together, and tick Move empty folders to the Recycle Bin.
- Click Add Rule. Pick Files with extension and add
.jpg,.jpeg,.heicand.png, choose Move to folder, and typeAll photosin Moves to. For every file whatever its type, use Files matching regex with the pattern.instead. - Press Run. The Confirm first scan dialog shows how many files will move, how many folders and how deep the scan went, and Sample moves, before anything moves.
- To repeat it, switch the folder to Scheduled, for example every day at 18:00. The app has to be running, in the tray or the menu bar.
The destination has to be a folder inside the main folder, like All photos, or another folder such as D:\Photos\All. A file already in its destination counts as organized, so File Arbor will not pile files into the very folder it is scanning.
Same names, undo and where a file came from
- Same name. With File conflict behavior on Rename, the default, the second file arrives as
IMG_0001 (1).jpg. Nothing is overwritten. If the setting is Overwrite, the first-scan dialog warns in red and offers to run the scan with Rename. - Keep the folder name. Switch on "Also change the file name" in the rule and, under Edit as text, write
<Folder>_<Name>. ThenRome/IMG_0001.jpgarrives asRome_IMG_0001.jpg. The rule's preview shows each new name before anything moves. - Undo. Undo right after the run puts every file back. In History, each move is listed with where it came from, and each can be undone on its own. Folders sent to the Recycle Bin are restored from there, not by the app.
- Want the tree, not a pile? Keep structure recreates the subfolders under the destination.
- Exclusions. Pick subfolders to keep out of the scan.
node_modules,.gitand similar folders are skipped already, and on a Mac the scan never goes inside apps or Photos libraries.
The free plan is one watched folder, two rules, up to 20 files a day, manual runs. Subfolder scanning, Scheduled mode and regex matching are Pro, which is $24.99 one-time (see pricing). Every option is listed in the subfolders section of the handbook.
If you flatten and then want to re-sort by date, see how to sort files into year and month folders.
How Do You Flatten a Folder Structure Without Losing Files?
Five habits:
- Preview first. Use
-WhatIfin PowerShell,-printin Terminal, or Confirm first scan in File Arbor. - Never use an overwrite option on photos or documents. A replaced file does not come back.
- Copy the folder first if the files matter and you are using a command.
- Check the count before and after. Explorer and Finder show item counts.
- Delete empty folders only after the move, once the counts agree.
Which Method Should You Use?
A few hundred files on Windows. File Explorer search.
Thousands of files, or a command you will rerun. PowerShell, with -WhatIf first.
On a Mac, files of one kind. Finder search with the Kind criterion.
Everything on a Mac, or an unindexed drive. Terminal.
A folder that keeps filling with new subfolders. File Arbor on Scheduled, particularly if you want same-name files numbered, folder names kept in the file names and empty folders removed in one go. To sort files into folders by a name pattern instead, see sorting files into folders by file name.
FAQ
How do I move all files from subfolders to the main folder in Windows 11?
Open the main folder, type * in the search box, sort by Type, select the files, cut them with Ctrl+X and paste them into the main folder. For thousands of files, one PowerShell line with Get-ChildItem and Move-Item does the same. Either way, the emptied subfolders stay behind and have to be deleted separately.
How do I flatten a folder structure on a Mac?
In Finder, press Command-F, scope the search to the folder, set Kind to the file type, select all, copy, then paste into the destination with Option-Command-V to move instead of copy. In Terminal, run find with -mindepth 2 and mv -n from the main folder. The emptied subfolders stay behind either way.
What happens to files with the same name when you flatten a folder?
It depends on the method. Explorer and Finder ask what to do and can keep both files with a number. PowerShell and mv -n leave the second file in its subfolder. File Arbor renames it with a number, such as IMG_0001 (1).jpg. Avoid any overwrite option on photos or documents, because the replaced file is gone.
Can I copy files from subfolders into one folder instead of moving them?
Yes. In Explorer use Ctrl+C and Ctrl+V on the search results, and in Finder use Command-V instead of Option-Command-V. In PowerShell, Copy-Item overwrites same-name files without asking, so copy the whole folder first and flatten the copy with the move commands. That keeps the original tree untouched.
How do I delete the empty subfolders afterwards?
On Windows, use a Command Prompt rd loop or a PowerShell line that removes empty directories. On a Mac, delete the .DS_Store files first, then run find with -type d -empty -delete. File Arbor Pro can also move empty folders to the Recycle Bin or Trash after each run, where you can restore them. The exact commands are in the guide to deleting empty folders.
The Bottom Line
Once, any built-in method does the job in minutes. When the folder keeps refilling, File Arbor Pro piles the files together on a schedule, numbers duplicates, keeps folder names if you want, and moves the empty folders to the Recycle Bin. Download File Arbor and try it on one folder: the free plan is one watched folder, two rules, up to 20 files a day, manual runs. Subfolder scanning and Scheduled mode come with Pro, $24.99 one-time with lifetime updates; see the pricing page.