我有一个文件A,里面有400条.md记录,另有一个B文件,包含A里面的400条外另有800条其他的.md记录。
怎么把这800条.md单独提取出来,另外建立一个文件。 win11 PC
# 创建目标文件夹
New-Item -ItemType Directory -Path "D:\提取出的800条" -Force | Out-Null
# 获取文件名列表
$A = Get-ChildItem "D:\A" -Recurse | ForEach-Object { $_.Name }
$B = Get-ChildItem "D:\B" -Recurse
# 筛选出额外的文件(按文件名对比)
$Extra = $B | Where-Object { $_.Name -notin $A }
# 复制文件(使用 -LiteralPath 避免通配符问题)
$Extra | ForEach-Object {
Copy-Item -LiteralPath $_.FullName -Destination "D:\提取出的800条" -Force
}
# 输出统计
Write-Host "总共复制了 $($Extra.Count) 个文件" -ForegroundColor Green