Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell: Move all files from folders and subfolders into single folder

Tags:

powershell

Trying to index and search for a file within 8K files and 2K folders..

Is there a simple Powershell script that can move all files from folders and/or subfolders into one main folder?

don't need to delete the empty folders but would help.

like image 837
tackdetack Avatar asked Jun 27 '16 21:06

tackdetack


People also ask

Is there a way to move files from multiple folders at once?

Click on the Drop stack tab to open it. Now we can drag and drop each file we want to copy into the drop stack area. Once we have all the files we want to copy in the drop stack area, we can open the folder we want to copy to, and simply drag and drop all the files from the drop stack to that folder.


2 Answers

The fourth example under help -Examples Move-Item is close to what you need. To move all files under the source directory to the dest directory you can do this:

Get-ChildItem -Path source -Recurse -File | Move-Item -Destination dest 

If you want to clear out the empty directories afterwards, you can use a similar command:

Get-ChildItem -Path source -Recurse -Directory | Remove-Item 
like image 149
Don Cruickshank Avatar answered Oct 02 '22 12:10

Don Cruickshank


Use .parent for the parent dir. It can be used recursively: .parent.parent

like image 29
Dikkie Dik Avatar answered Oct 02 '22 14:10

Dikkie Dik