Copy-Item copies directory as well as contents to UNC path

試著忘記壹切 提交于 2019-12-03 04:02:43

问题


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

回答1:


Try:

$from = "c:\temp\rhysc\*"



来源:https://stackoverflow.com/questions/1905553/copy-item-copies-directory-as-well-as-contents-to-unc-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!