powershell - Copy-Item 将项目移动到另一个位置而不创建父目录

标签 powershell powershell-2.0 powershell-3.0

如果我想移动以下结构

Parent
  ChildParent
    ChildOfAChildParent

到以下位置:

NewParent
  NewChildParent <-- here

运行以下命令时,我得到以下信息

Copy-Item "\Parent\ChildParent\ChildOfAChildParent" -Destination "NewParent\NewChildParent" -Recurse

NewParent
  NewChildParent
    ChildOfAChildParent

这不是我想要的行为,我不知道如何实现。我只想将文件和文件夹从 ChildOfAChildParent 转储到 NewChildParent 中,而不创建新的父目录。

最佳答案

我能够通过在我的路径中添加 \* 来解决这个问题(很少),所以它实际上是:

Copy-Item "\Parent\ChildParent\ChildOfAChildParent\*" -Destination "NewParent\NewChildParent" -Recurse

关于powershell - Copy-Item 将项目移动到另一个位置而不创建父目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24805320/

相关文章:

powershell - 为什么 Powershell ISE 显示 Powershell 控制台不显示的错误?

powershell - 使用 powershell windows azure commandlet,如何执行 Reset-RoleInstance 并等待操作完成

powershell - Powershell:在AD中检查重复的电子邮件

azure - 无法使用 Azure DevOps Pipeline 更新 RBAC 角色

powershell - “How to Read an SDK”是否为PowerShell更新?

powershell - 如何在 PowerShell 中传递可选参数?

powershell - 用于在Active Directory中提取各种数据字段的Powershell脚本

powershell - powershell开始作业对脚本 block 不执行任何操作

powershell - 从另一个powershell脚本调用一个powershell脚本并保证它是UTF8

windows - 将字符串 $variable 传递给 invoke-command 脚本 block 参数 -name