Question

Say you have this folder

foo

You can run this command in Bash

cp -r --no-target-directory foo bar

and it will create

foo
bar # same contents as foo

Then you can re-run the command without changing the result. How can you do this with PowerShell?

Was it helpful?

Solution 2

So the problem is that

cp -r -fo foo bar

only works if bar does not exist and

cp -r -fo foo/* bar

only works if bar exists. So to work around, you need to make sure bar exists before doing anything

md -f bar
cp -r -fo foo/* bar

OTHER TIPS

This will do that. It will create the bar folder, which will contain everything that foo contains.

copy-item .\foo .\bar -recurse -force
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top