Copy-Item 将目录及其内容复制到 UNC 路径
我正在尝试使用 PowerShell 1.0 获取文件夹的内容并将其复制到另一个文件夹。非常简单的东西,如果我从本地文件夹复制到本地文件夹,则使用 Copy-Item $from $to -recurse 一切正常。但是,如果 $to
变量是 UNC 路径,则它似乎会复制 $from
目录,而不仅仅是其内容。
例如
$from = "c:\temp\rhysc\"
$to = "\\OtherMachineName\ShareFolder\"
Copy-Item $from $to -recurse
...最终创建一个文件夹 \\OtherMachineName\ShareFolder\rhysc
而不是仅仅复制该文件夹的内容。
我想维护我正在复制的 $from
目录的结构,因此我对管道的基本尝试不起作用(所有内容都转储到 $to
的根目录中> 文件夹)
Get-ChildItem $from -recurse | Copy-Item -destination $to
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.
e.g.
$from = "c:\temp\rhysc\"
$to = "\\OtherMachineName\ShareFolder\"
Copy-Item $from $to -recurse
...ends up up creating a folder \\OtherMachineName\ShareFolder\rhysc
instead of just copying over the contents of the folder.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
$from = "c:\temp\rhysc\*"
Try:
$from = "c:\temp\rhysc\*"