开发者

PowerShell implementation of xcopy

Is there a way to replicate an xcopy functional using powershell?

I thought it was an easy question until I tried some cmdlets.

开发者_运维知识库

Let's imagine I've got a folder structure like:

src

|-a

|-b

There're files in each folder of course. I need to copy contents of Src to some folder Dst.

With xcopy it'd be like this:

xcopy src dst\ /e /y

PS analog would be something like this:

copy-item src dst\ -force -recurse -verbose

Works great... the first time. The second time it creates a subfolder dst\src and puts files there!

I can't figure out any easy workaround. Can you?

p.s. I know I can use xcopy in PS.


copy-item c:\\src\\* c:\\dst -force -recurse -verbose 


Here's another workaround I found here: https://github.com/nightroman/PowerShellTraps/tree/master/Cmdlets/Copy-Item/Inconsistent-destination I've tried in the past to do this myself and would revert back to xcopy. This is "idempotent" and will have the same result the second time.

mkdir $destination -Force
Copy-Item $source\* $destination -Recurse -Force
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜