Powershell 2.0 - 将文件复制到其他位置

时间:2016-03-05 15:03:56

标签: powershell powershell-v2.0

如何编写powershell脚本将文件复制到其他位置,包括子文件夹。示例copy fileA从folderA到folderB,如果folderB中有任何子文件夹,fileA也会复制到该子文件夹。

1 个答案:

答案 0 :(得分:1)

嗯,你可以很容易地用两个命令来完成它:

# Copy file A to folder B.
Copy-Item -Path $fileA -Destination $folderB

# Get all subdirectories of folder B and copy file A to them. 
Get-ChildItem -Path $folderB -Recurse | 
? { $_.PSIsContainer } |
% { Copy-Item -Path $fileA -Destination $_.FullName }

如果能用一个命令完成,对我来说并不是很明显。至少不优雅。

相关问题