【发布时间】:2019-05-02 20:54:00
【问题描述】:
我正在尝试使用 powershell 脚本将所有文件夹/子文件夹/子文件从服务器上的一个文件夹移动到另一个文件夹,同时始终保持相同的文件结构。为此,我正在使用 Get-childItem |复制项目。除了目录中的第一个文件夹外,所有文件夹、子文件夹和子文件都在正常移动。而是将此文件夹中的所有这些子文件/子文件夹输出到目标。但是,它确实保留了它们的结构,只是不包括它们的父目录。我的代码如下:
Get-ChildItem $sourceFilePath -Force | Copy-Item -Destination ("*file path*" -f $destinationServer, $destinationClient) -Recurse -Force
- filepath 被改写以提高可读性
- $sourceFilePath 是我要复制的源文件夹
- $destination server / $destinationClient 是在解释的“文件路径”中使用的变量
我无法弄清楚为什么此代码适用于所有其他文件夹、子文件夹和文件,除了这个单个文件夹及其项目。任何帮助将不胜感激,如果有任何其他信息可以帮助,请告诉我。
感谢@Christian Müller 的回答:
New-Item $destinationFilePath -name "MissingFolder" -type directory -Force | Out-Null
Get-ChildItem $sourceFilePath -Force | Copy-Item -Destination ("*filepath*" -f $destinationServer, $destinationClient) -Recurse -Force
【问题讨论】:
标签: powershell