Solved

copy-item : create source folder in destination

Posted on 2013-11-18
5
1,178 Views
Last Modified: 2013-11-18
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
0
Comment
Question by:Sybux
  • 2
  • 2
5 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 39656852
Why not..
Copy-item -path r:\bob -Destination P:\ -Recurse -Force
0
 

Author Comment

by:Sybux
ID: 39656939
because time to time, destination name is not original name :) It should be too easy
0
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
ID: 39656968
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
 
LVL 40

Expert Comment

by:Subsun
ID: 39656969
Try..
copy-item -path "r:\bob\" -Destination p:\bob -Force -Recurse

Open in new window

0
 

Author Closing Comment

by:Sybux
ID: 39657043
get-ChildItem was the tip. Thanks
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
A procedure for exporting installed hotfix details of remote computers using powershell
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question