![](/img/trans.png)
[英]How can I bulk move files from one folder to another based on filenames?
[英]Move files from one folder to another from a list of filenames from a text file
該腳本可用於C:\\ThirdParty
並根據需要進行調整。
$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
}
}
使用Get-Content
,您可以在名為$file_list
的數組中檢索文件列表(每行一個)。
您設置一個$search_folder
,然后為每個文件進行循環查找,並在文件夾及其子文件夾中遞歸查找。 如果找到文件,則將其移至$destination_folder
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.