![](/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.