Powershell 2.0 - 将文件复制到其他位置
Powershell 2.0 - Copy file to other location
如何编写powershell脚本将文件复制到其他位置,包括子文件夹。示例将文件A从文件夹A复制到文件夹B,如果文件夹B中有任何子文件夹,文件A也会复制到该子文件夹。
嗯,你可以很容易地用两个命令来完成:
# 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 }
是否可以用一个命令完成对我来说不是很明显。至少不优雅。
如何编写powershell脚本将文件复制到其他位置,包括子文件夹。示例将文件A从文件夹A复制到文件夹B,如果文件夹B中有任何子文件夹,文件A也会复制到该子文件夹。
嗯,你可以很容易地用两个命令来完成:
# 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 }
是否可以用一个命令完成对我来说不是很明显。至少不优雅。