Copy-Item 将目录和内容复制到 UNC 路径 [英] Copy-Item copies directory as well as contents to UNC path
问题描述
我正在尝试使用 PowerShell 1.0 获取文件夹的内容并将其复制到另一个文件夹.非常简单的东西,如果我从本地文件夹复制到本地文件夹,则使用 Copy-Item $from $to -recurse
一切正常.然而,如果 $to
变量是一个 UNC 路径,它似乎复制了 $from
目录,而不仅仅是它的内容.
I'm trying to take the contents of a folder and copy it to another using PowerShell 1.0. Pretty simple stuff and it all works fine using Copy-Item $from $to -recurse
if I am copying from a local folder to a local folder. However, if the $to
variable is a UNC path, it seems to copy the $from
directory, not just its contents.
例如
$from = "c:\temp\rhysc\"
$to = "\\OtherMachineName\ShareFolder\"
Copy-Item $from $to -recurse
...最终会创建一个文件夹 \\OtherMachineName\ShareFolder\rhysc
而不是仅仅复制文件夹的内容.
...ends up up creating a folder \\OtherMachineName\ShareFolder\rhysc
instead of just copying over the contents of the folder.
我想维护我正在复制的 $from
目录的结构,所以我在管道方面的基本尝试没有奏效(所有内容都被转储到了 $to
文件夹)
I want to maintain the structure of the $from
directory that I am copying over so my basic attempt at piping didn't work (everything got dumped in the root of the $to
folder)
Get-ChildItem $from -recurse | Copy-Item -destination $to
推荐答案
尝试:
$from = "c:\temp\rhysc\*"
这篇关于Copy-Item 将目录和内容复制到 UNC 路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!