I have a list of files in a file named files.txt.
I have a folder, FlacTest, with a mix of files that appear in the list and files that don't.
I want to move the files that appear in the list out of the folder FlacTest and into a second folder - FlacRecovery.
Here is my code:
$file_list = Get-Content 'C:\files.txt'
$search_folder = 'C:\FlacTest'
$destination_folder = 'C:\FlacRecovery'
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}
}
When I run the script it does not error but nothing happens. Is there something wrong with the code?
if ($file_to_move.Exists) { $file_to_move | Move-Item -Destination $destination_folder} }and remove| % { $_.FullName}