PowerShell is a powerful scripting language that is well-suited for tasks like this. Here’s an example PowerShell script that reads a list of filenames from a text file and copies them from one folder to another:
# Specify the paths
$sourceFolder = "C:\Path\To\Source\Folder"
$destinationFolder = "C:\Path\To\Destination\Folder"
$filenameListPath = "C:\Path\To\FilenameList.txt"
# Read the list of filenames from the text file
$filenames = Get-Content $filenameListPath
# Ensure the destination folder exists, create it if necessary
New-Item -ItemType Directory -Force -Path $destinationFolder
# Iterate through the filenames and copy them to the destination folder
foreach ($filename in $filenames) {
$sourcePath = Join-Path -Path $sourceFolder -ChildPath $filename
$destinationPath = Join-Path -Path $destinationFolder -ChildPath $filename
if (Test-Path $sourcePath) {
Copy-Item -Path $sourcePath -Destination $destinationPath -ErrorAction SilentlyContinue
Write-Host "File '$filename' copied to '$destinationFolder'"
} else {
Write-Host "File '$filename' not found in '$sourceFolder'"
}
}
Replace "C:\Path\To\Source\Folder"
, "C:\Path\To\Destination\Folder"
, and "C:\Path\To\FilenameList.txt"
with your actual source folder, destination folder, and the path to your filename list, respectively.
Save this script with a .ps1 extension (e.g., CopyFiles.ps1) and execute it in a PowerShell environment.
This script will copy files from the source folder to the destination folder based on the filenames listed in the text file. If a file is not found in the source folder, it will display a message indicating that the file was not found.