Often you may want to move all files from all folders and subfolders in a particular directory into a single folder using PowerShell.
You can use the following syntax to do so:
Get-ChildItem -Path $source_dir -Recurse -File | Move-Item -Destination $destination_dir
This particular example moves the files from all folders and subfolders in the directory specified by the path in the $source_dir variable into a single folder specified by the path in the $destination_dir variable.
The following example shows how to use this syntax in practice.
Example: Move All Files from Folders and Subfolders into One Folder
Suppose our current directory has the following location:
- c:\users\bobbi\data1
We can use the following syntax to view all folders and subfolders in this current directory:
Get-ChildItem -Directory -Recurse
The following screenshot shows how to use this syntax in practice:

We can see that the current directory contains the following folder structure:
- east_data
- west_data
- backup_data
Suppose that we would like to move all files from each of these folders and subfolders into one single folder with the following location:
- c:\users\bobbi\data2
We can use the following syntax to do so:
$source_dir = 'c:\users\bobbi\data1'
$destination_dir = 'c:\users\bobbi\data2'
Get-ChildItem -Path $source_dir -Recurse -File | Move-Item -Destination $destination_dir
The following screenshot shows how to use this syntax in practice:

When we use the Get-ChildItem cmdlet to view all files in the destination folder, we can see that all files from the folders and subfolders in the source folder have been moved into the destination folder.
Related Tutorials
The following tutorials explain how to perform other common tasks in PowerShell:
PowerShell: How to Copy and Rename a File
PowerShell: How to Move and Rename a File
PowerShell: How to Rename File Extension of Multiple Files
PowerShell: How to Delete All Files with Specific Extension
