Thursday, April 12, 2018

Bulk copy files from one folder to another using powershell

Suppose you have a thousands of files in one folder and its sub folders and you have given a task to filter out few files which you already identified is available but to find each file and copy them to other folder is quite tedious one. especially urgency of files filter is very high.

to overcome this issue and resolve this situation very smoothly i have come up with given power shell command which i am hoping to helpful to you people as well.

$file_list = Get-Content C:\fileslist.txt
$search_folder = "C:\SourceFolder"
$destination_folder = "C:\Backup\DestinationFolder"

foreach ($file in $file_list) {
    $file_to_move = Get-ChildItem -Path $search_folder -Filter $file -Recurse -ErrorAction SilentlyContinue -Force | % { $_.FullName}
    if ($file_to_move) {
        Move-Item $file_to_move $destination_folder
    }
}

all you need to do is fill your list of files in filelist.txt file and run the below power shell command. after successful completion you will able to see the filtered files in your destination folder location.


Hope this Helps!!!! 

No comments:

Post a Comment