I have a text file which contains a list of file names with extension(no spaces in the filename).

I have two folders in two different paths, say, C:\ThirdParty and C:\Users. There will be subfolders in these paths.
I need to search each filename in the text file on these two folders and its subfolders and move the exact matching files to another folders say, C:\Backup\ThirdParty and C:\Backup\Users.
How can i do this in Windows 7 with powershell or command prompt.
I have no idea how to start or I am zero at powershell and DOS commands.
This script can be used for C:\ThirdParty and adapted for you needs.
$file_list = Get-Content C:\list.txt
$search_folder = "C:\ThirdParty"
$destination_folder = "C:\Backup\ThirdParty"
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
}
}
With Get-Content you retrieve the list of your files (one per line) in an array called $file_list.
You set a $search_folder and then a loop for each file looking recursively in the folder and its subfolders. If the file is found, is moved to $destination_folder
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With