此脚本在PowerShell中完美工作。它复制具有特定类型的所有文件。但我想复制文件与它的文件夹&子文件夹。如何复制文件夹与子文件夹?
$dest = "C:\example"
$files = Get-ChildItem -Path "C:\example" -Filter "*.msg" -Recurse
foreach ($file in $files) {
$file_path = Join-Path -Path $dest -ChildPath $file.Name
$i = 1
while (Test-Path -Path $file_path) {
$i++
$file_path = Join-Path -Path $dest -ChildPath
"$($file.BaseName)_$($i)$($file.Extension)"
}
Copy-Item -Path $file.FullName -Destination $file_path
}
请解释更多的细节,你想什么功能都有。一些实际的例子将是一个好的开始。 – vonPryz
嗨,例如,文件夹中有1000个.txt文件。这会成功复制该文件,但不包含包含该文件的文件夹。 –
简而言之,它不复制文件夹,而是复制文件。 –