copy-item : create source folder in destination

Hi,

I'm trying to make a very simple copy of a folder from one location to another location like this :

copy-item -path r:\bob -Destination p:\bob

Problem is that copy-item create a bob subfolder in the destination so that I'm getting this :

p:\Bob\bob ?!!?

What the hell is the command to avoid this ?

Thx in advance
SybuxAsked:
Who is Participating?
 
footechCommented:
If the destination doesn't already exist, it will do as you want.  If it does exist, then the following will copy the source folder and all subfolders.
copy-item -path r:\bob\* -Destination p:\bob -recurse

Open in new window


If you only wanted to copy the files directly in the source folder and ignore subfolders, then you would have to do a Get-ChildItem and pipe the results to Copy-Item.
0
 
SubsunCommented:
Why not..
Copy-item -path r:\bob -Destination P:\ -Recurse -Force
0
 
SybuxAuthor Commented:
because time to time, destination name is not original name :) It should be too easy
0
 
SubsunCommented:
Try..
copy-item -path "r:\bob\" -Destination p:\bob -Force -Recurse

Open in new window

0
 
SybuxAuthor Commented:
get-ChildItem was the tip. Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.