Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 226
Kostassoid Avatar asked Sep 07 '11 09:09

Kostassoid


People also ask

Can I use xcopy in PowerShell?

xcopy is the windows command. It works with both PowerShell and cmd as well because it is a system32 utility command.

Does xcopy still work in Windows 10?

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.

How does the xcopy command work?

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.


1 Answers

copy-item c:\\src\\* c:\\dst -force -recurse -verbose  
like image 153
CB. Avatar answered Oct 14 '22 20:10

CB.