Sha*_*ron 2 powershell cmd command-prompt windows-7
我有一个文本文件,其中包含带有扩展名的文件名列表(文件名中没有空格)。
我在两个不同的路径中有两个文件夹,比如 C:\ThirdParty 和 C:\Users。这些路径中会有子文件夹。
我需要在这两个文件夹及其子文件夹的文本文件中搜索每个文件名,并将完全匹配的文件移动到另一个文件夹,例如 C:\Backup\ThirdParty 和 C:\Backup\Users。
如何在 Windows 7 中使用 powershell 或命令提示符执行此操作。
我不知道如何开始,或者我在 powershell 和 DOS 命令方面为零。
此脚本可用于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
}
}
Run Code Online (Sandbox Code Playgroud)
随着Get-Content
您在名为$file_list
.
您$search_folder
为在文件夹及其子文件夹中递归查找的每个文件设置一个循环。如果找到文件,则移动到$destination_folder
归档时间: |
|
查看次数: |
10174 次 |
最近记录: |