【发布时间】:2016-03-06 00:30:32
【问题描述】:
如何编写 powershell 脚本将文件复制到其他位置,包括子文件夹。示例将fileA从文件夹A复制到文件夹B,如果文件夹B中有任何子文件夹,则fileA也会复制到该子文件夹。
【问题讨论】:
-
你有没有搜索过这个问题?
Get-Help Copy-Item -Full
如何编写 powershell 脚本将文件复制到其他位置,包括子文件夹。示例将fileA从文件夹A复制到文件夹B,如果文件夹B中有任何子文件夹,则fileA也会复制到该子文件夹。
【问题讨论】:
Get-Help Copy-Item -Full
嗯,你可以很容易地用两个命令来完成:
# 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 }
如果可以用一个命令完成,对我来说并不是很明显。至少不优雅。
【讨论】: