I want copy whole folder to another folder using Copy-Item
.
My source folder c:\base
contains some files:
├───base
│ file1.txt
│ file2.txt
I use the following command:
Copy-Item c:\base c:\target -recurse
if the target folder (c:\target
) exists, the command copies source folder exactly as I want:
├───target
│ └───base
│ file1.txt
│ file2.txt
If the target folder doesn't exist, the command creates target folder (exactly as I want), but now it copies only the content of the source folder (without the base
folder):
├───target
│ file1.txt
│ file2.txt
Select the file you want to copy by clicking on it once. Right-click and pick Copy, or press Ctrl + C . Navigate to another folder, where you want to put the copy of the file. Click the menu button and pick Paste to finish copying the file, or press Ctrl + V .
It is a known bug ( feature some would say):
http://groups.google.com/group/microsoft.public.windows.powershell/msg/3327f2d1544e7fb6?as_umsgid=6CAEDDC7-0F1A-4B21-8FB0-E6102A16EB51@microsoft.com
This behaviour IMO, is an artifiact of the provider and object pipeline model that powershell uses. You have to get used to the idea that the navigational context is a bit weird compared to other shells; it's explicit as opposed to implicit, since the filesystem is one of many contexts that can be used. This brings with it some weird behaviours since the targets of any given path are handled with a combination of powershell's generic grammar and the command itself, as opposed to being entirely handled by the command in shells like command.com/cmd.exe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With