我写的脚本MS置。这个脚本用的 Copy-Item 命令。一个可选择的参数,以此命令"-container".该文件的参数国家,指定这一论点"保存容器的对象,在复制过程中的操作。"

这是都好和好,因为我将是最后一个人希望无防腐剂容器的对象在一个复制的运作。但在所有的严重性,这是什么论?特别是在这种情况下我在哪里复制了一盘录树从一个地方到另一个地方,什么差这么做的行为 Copy-Item 命令?

有帮助吗?

解决方案

文档所讨论的容器是文件夹结构。如果您正在进行递归复制并希望保留文件夹结构,则可以使用-container开关。 (注意:默认情况下-container开关设置为true,所以你真的不需要指定它。如果你想关掉它,你可以使用 -container:$ false 。)

有一个问题...如果您执行目录列表并将其传递给Copy-Item,它将不会保留文件夹结构。如果要保留文件夹结构,则必须指定-path属性和-recurse开关。

其他提示

我也发现的文件少于有帮助的。我做了一些测试看看 -Container 参数工作的结合 -Recurse 当复印文件和文件夹。

注意, -Container 装置 -Container: $true.

这是该文件的结构,我用的例子:

#    X:.
#    ├───destination
#    └───source
#        │   source.1.txt
#        │   source.2.txt
#        │
#        └───source.1
#                source.1.1.txt
  • 对于所有的实例,当前的位置(pwd)是 X:\.
  • 我用PowerShell4.0。

1)复制只是源文件夹(空的文件夹):

Copy-Item -Path source -Destination .\destination
Copy-Item -Path source -Destination .\destination -Container
#    X:.
#    ├───destination
#    │   └───source
#    └───source (...)

下面给出了一个错误:

Copy-Item -Path source -Destination .\destination -Container: $false
# Exception: Container cannot be copied to another container. 
#            The -Recurse or -Container parameter is not specified.     

2)复制整个文件夹结构与文件:

Copy-Item -Path source -Destination .\destination -Recurse
Copy-Item -Path source -Destination .\destination -Recurse -Container
#    X:.
#    ├───destination
#    │   └───source
#    │       │   source.1.txt
#    │       │   source.2.txt
#    │       │
#    │       └───source.1
#    │               source.1.1.txt
#    └───source (...)    

3)复制的所有后裔(文件和文件夹)成一个单一的文件夹:

Copy-Item -Path source -Destination .\destination -Recurse -Container: $false
#    X:.
#    ├───destination
#    │   │   source.1.1.txt
#    │   │   source.1.txt
#    │   │   source.2.txt
#    │   │
#    │   └───source.1
#    └───source (...)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top