【问题标题】:Replace files in a folder with files in other folder, using powershell使用powershell将文件夹中的文件替换为其他文件夹中的文件
【发布时间】:2015-11-13 14:46:50
【问题描述】:

我有两个文件夹。

  1. Folder1 包含许多文件。

  2. Folder2 是用于 folder1 中一组文件的服务包。

我想通过 PowerShell 将 Folder1 中的特定文件替换为 Folder2 中的文件。

-Replace 是正确的起点吗?我应该如何处理?

更新

Get-ChildItem $hotfix | ForEach-Object {Copy-Item $_.FullName -Destination $original -force}

【问题讨论】:

  • 查看copy-item-force 以覆盖,返回一些您尝试过但遇到问题的示例。 -Replace 更多的是字符串替换相关而不是文件/目录相关。
  • 我尝试了以下代码,它运行良好 -Get-ChildItem $hotfix | ForEach-Object {Copy-Item $_.FullName -Destination $original -force}
  • 干得好,干得好。
  • @ruchasn 发布答案!

标签: powershell powershell-2.0 powershell-ise


【解决方案1】:

对不起,我发布的答案晚了。但在这里!!

所以, 1.文件夹1命名为$original 2.文件夹2命名为$hotfix

Get-ChildItem $hotfix | ForEach-Object {Copy-Item $_.FullName -Destination $original -force}

这会将 $original 和 $hotfix 的所有通用文件替换为 $hotfix 中的文件!

【讨论】:

    猜你喜欢
    • 2019-03-09
    • 2020-04-30
    • 1970-01-01
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-17
    相关资源
    最近更新 更多