If you have a folder with multiple subfolders containing files that you need to move or copy to a single folder, it can be a tedious and time-consuming process to do it manually. Luckily, Windows provides a few built-in methods to quickly move or copy all files from subfolders to the main folder. In this article, we’ll explore different ways to move files from multiple folders to one folder in Windows 11 and Windows 10.
Also see: How to Batch Rename Files in Windows 11
Page Contents
Why do you need to move or copy all files from subfolders to the main folder?
There are various reasons why you might need to move or copy all files from subfolders to the main folder. For instance, you might want to backup all files from different subfolders to a single location, or you might want to move all your photos or videos from different subfolders on a phone or tablet to a single folder on a PC in order to sort the files by date, location, or event.
Suggested read: How to Compare Two Folders in Windows 11
Method 1: Using PowerShell
PowerShell is a command-line shell and scripting language that is built on top of the .NET Framework. It is similar to the Command Prompt but provides more advanced features and functionality. You can use PowerShell to move or copy all files from subfolders to the main folder. Here’s how:
- Go to Start menu and search for “PowerShell“.
- Right-click “Windows PowerShell” and select “Run as administrator“.
- Type the following command to create a new folder for all the files to be copied/moved to:
New-Item -ItemType Directory -Path "c:\MainFolder"
This command creates a new directory named “MainFolder” on the drive D:. You can replace “c:\MainFolder” with any other path and folder name of your choice. - Type the following command to change the current directory to the source folder that contains the subfolders:
Set-Location -Path "c:\FolderWithSubfolders\"
This command changes the current directory to “c:\FolderWithSubfolders\”, which is the folder that contains the subfolders with the files you want to move or copy. You can replace the path and folder name with the actual location of the source folder. - Type the following command to copy all the files in the subfolders to the new folder:
Get-ChildItem -Recurse -File | Copy-Item -Destination "c:\MainFolder\"
This command uses the “Get-ChildItem” cmdlet to get all the files in the subfolders and the “-Recurse” parameter to include all subfolders. The “-File” parameter is used to exclude directories from the results. The “Copy-Item” cmdlet is used to copy the files to the destination folder. You can replace “Copy-Item” with “Move-Item” if you want to move the files instead of copying them.
Note that if a file with the same name exists in the destination folder, you’ll be prompted to overwrite or skip the file.
Method 2: Using Command Prompt
The Command Prompt is a powerful tool in Windows that allows you to execute commands to perform various tasks. You can use Command Prompt to move or copy all files from subfolders to the main folder. Here’s how:
- Go to Start menu and search for “cmd“.
- Right-click Command Prompt and select “Run as administrator“.
- Type the following command to create a new folder for all the files to be copied/moved to:
md "c:\MainFolder"
This command creates a new directory named “all snaps” on the drive D:. You can replace “d:\all snaps” with any other path and folder name of your choice. - Type the following command to change the current directory to the source folder that contains the subfolders:
cd /d "c:\FolderWithSubfolders\"
This command changes the current directory to “c:\FolderWithSubfolders\”, which is the folder that contains the subfolders with the files you want to move or copy. You can replace the path and folder name with the actual location of the source folder. - Type the following command to copy all the files in the subfolders to the new folder:
for /r %d in (*) do copy "%d" "c:\MainFolder\"
This command uses the “for” command to loop through all the files in the subfolders and the “copy” command to copy the files to the destination folder. You can replace “copy” with “move” if you want to move the files instead of copying them.
If a file with the same name exists in the destination folder, you’ll be prompted to overwrite or skip the file.
Method 3: Using File Explorer Search
The File Explorer search function allows you to find all files in a folder and its subfolders based on various criteria like file type, size, and date modified. You can use the File Explorer search function to move or copy all files from subfolders to the main folder. Here’s how:
- In File Explorer, navigate to the folder that contains the subfolders with the files you want to move or copy.
- Type the following in the Search bar and press Enter.
*.* NOT type:"file folder"
The*.*
parameter is to search for all files with any name and any extension. TheNOT type:"file folder"
parameter is to tell File Explorer to exclude folders from the search results, as we only want to see the files within those folders. - Wait for the search to complete. Read: Windows 11 search slow? How to speed up search in File Explorer.
- Select all files using Ctrl + A.
- Right-click the selected files and choose Cut (or Copy if you want to copy those files instead of moving).
- Navigate to the main folder and then paste the files into it.
Tip: You can also perform a more specific search, such as searching only video files or picture files, using the “kind” parameter in File Explorer on Windows 11 or Windows 10.
If the subfolder in question has multiple subfolders and you want to move all the files without their subfolder structure in tact, this method can be useful.
Related issue: “This Folder is Empty” in Windows 11 (Fix)
Method 4: Using a Batch File
A batch file is a script file that contains a series of commands to be executed in sequence. You can use a batch file to move or copy all files from subfolders to the main folder. Here’s an example batch file:
@echo off
set SOURCE_FOLDER=C:\Mainfolder\
set DESTINATION_FOLDER=c:\FolderWithSubfolders\
if not exist "%DESTINATION_FOLDER%" (
mkdir "%DESTINATION_FOLDER%"
)
for /r "%SOURCE_FOLDER%" %%f in (*) do (
move "%%f" "%DESTINATION_FOLDER%\"
)
echo All files have been moved to %DESTINATION_FOLDER%.
pause
You can copy the codes above and paste to a new text file. Replace the source folder and destination folder locations, and save it as “copyfiles.bat”. Run the batch file and it will automatically copy all files from subfolders of the source folder to the destination folder.
This batch file sets the source and destination folders as variables and creates the destination folder if it doesn’t exist. Then, it uses a “for” loop to copy or move all the files in the source folder and its subfolders to the destination folder. The “if” statement is used to exclude directories from the results.
Additional Tips
- Before you move or copy all files from subfolders to the main folder, make sure to check if there are any duplicate filenames to avoid overwriting or losing any data.
- You can also use a file synchronization tool like FreeFileSync or SyncToy to automate the process of moving or copying files from subfolders to the main folder. These tools can compare the files in the source and destination folders and only copy or move the files that have changed or been added.
- Always make a backup of your files before moving or copying them, in case of accidental deletion or corruption.
- If you want to move or copy all files from multiple folders to a single folder, you can use the same methods outlined in this article by specifying the different source folders in the commands or scripts.
- The methods outlined in this article work on Windows 11 and Windows 10, but they may also work on earlier versions of Windows with some modifications.
Wrap-up
Moving or copying all files from subfolders to the main folder can be a time-consuming and tedious task, but with the methods outlined in this article, you can do it quickly and easily. Whether you prefer to use the Command Prompt, File Explorer search, PowerShell, a batch file, or a file synchronization tool, the steps are simple and can save you a lot of effort. Try these methods the next time you need to move or copy all files from subfolders to the main folder in Windows.