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.
xcopy is the windows command. It works with both PowerShell and cmd as well because it is a system32 utility command.
While still included in Windows 10, XCOPY has been deprecated in favor of robocopy , a more powerful copy tool, which is now supplied with the Microsoft Windows Server and Desktop operating systems. DR DOS 6.0 and Datalight ROM-DOS include an implementation of the XCOPY command.
By default, xcopy prompts you to specify whether Destination is a file or a directory. Copies directories and subdirectories, unless they are empty. If you omit /s, xcopy works within a single directory. Copies all subdirectories, even if they are empty.
copy-item c:\\src\\* c:\\dst -force -recurse -verbose
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With