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
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?
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