【问题标题】:Powershell 2.0 - Copy file to other locationPowershell 2.0 - 将文件复制到其他位置
【发布时间】:2016-03-06 00:30:32
【问题描述】:

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

【问题讨论】:

  • 你有没有搜索过这个问题? Get-Help Copy-Item -Full

标签: powershell powershell-2.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 }

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

【讨论】:

  • Get-ChildItem : 找不到与参数名称“目录”匹配的参数。
  • 嗯,我猜这个参数是在2.0之后添加的。我会尽快修改它。
猜你喜欢
  • 1970-01-01
  • 2015-07-01
  • 1970-01-01
  • 2018-10-14
  • 2011-08-10
  • 2021-09-18
  • 1970-01-01
  • 1970-01-01
  • 2018-09-15
相关资源
最近更新 更多