Powershell copy or move files from multiple folder to another folder

In the daily data processing task, we always need to copy or move files from multiple source place to one destination folder. In this blog, I’ll show you how to do those task quickly and easily via PowerShell.

Sample Code

I am using below code to move all csv files under Archives folder to Source folder. Archives folder has more than thousands sub-folders.

get-childitempath e:\archives\*.csv -recurse | move-item -destination d:\source

Get-childitem

Get-ChildItem by default only can get the items in one or more specified folder, to perform sub-folders copy and move , we need to user parameter -recurse .

Pip the result

To perform loop copy or move, we need to pipe (|) the recurse result first, then we can use move-item and copy-item cmdlets to do copy or move.

Leave a Reply

Your email address will not be published. Required fields are marked *