![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Copy-Item : Container cannot be copied onto existing leaf item. I have a file rrr.config that contains the [line Backup,"c:\clean", "C:\backup"] I run the script : $args = get-content -path c:\rrr.config #Make backups If ((select-string -path c:\rrr.config -pattern "Backup") -ne "") { $back = select-string -path c:\rrr.config -pattern "Backup" foreach ($match in $back) { $frname = $match.ToString().Split("""")[1] + "\*" $toname = $match.ToString().Split("""")[3] copy-item $frname -destination $toname -Verbose -recurse -force } } The folder clean contains several files and sub folders. If the backup folder does not exisit then I get the message : "Copy-Item : Container cannot be copied onto existing leaf item." and only the files in the folder clean are copied not the subfolders and their content. If the folder backup exists all the files and subfolders in clean are copied over to the backup folder. This happens with version 1 and 2.0 CPT 3 of powershell. Verbose listing of output: VERBOSE: Performing operation "Copy Directory" on Target "Item: C:\clean\absdde Destination: C:\backup". VERBOSE: Performing operation "Create Directory" on Target "Destination: C:\backup". VERBOSE: Performing operation "Copy File" on Target "Item: C:\clean\absdde\oadist.exe Destination: C:\backup\oadist.exe". VERBOSE: Performing operation "Copy File" on Target "Item: C:\clean\absdde\ReadMe.txt Destination: C:\backup\ReadMe.txt". VERBOSE: Performing operation "Copy File" on Target "Item: C:\clean\absdde\RegClean.exe Destination: C:\backup\RegClean.exe". Copy-Item : Container cannot be copied onto existing leaf item. At line:14 char:17 + copy-item <<<< $frname -destination $toname -Verbose -recurse -force + CategoryInfo : InvalidArgument: (C:\clean\CallRecording:String) [Copy-Item], PSArgumentException + FullyQualifiedErrorId : CopyContainerItemToLeafError,Microsoft.PowerShell.Commands.CopyItemCommand Copy-Item : Container cannot be copied onto existing leaf item. At line:14 char:17 + copy-item <<<< $frname -destination $toname -Verbose -recurse -force + CategoryInfo : InvalidArgument: (C:\clean\sec:String) [Copy-Item], PSArgumentException + FullyQualifiedErrorId : CopyContainerItemToLeafError,Microsoft.PowerShell.Commands.CopyItemCommand Any ideas what is going on. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Copy-Item : Container cannot be copied onto existing leaf item. If you qualify the path with an asterisk, Copy-Item will copy the complete dir structure with their items only if the destination already exists. Check out this thread's first reply: http://groups.google.com/group/micro...9b8b4424c2af22 To ensure the script executes successfully, check for the existence of the destination directory, and only append the asterisk to the source directory name if the destination directory exists. ... foreach ($match in $back) { $frname = $match.ToString().Split("""")[1] + '\' $toname = $match.ToString().Split("""")[3] if (Test-Path $frname -PathType Container) {$frname += '*'} copy-item $frname -destination $toname -Verbose -recurse -force } @PSTeam, This quirk needs to be documented, or at least explained in future Copy-Item help docs. -- Kiron |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Copy-Item : Container cannot be copied onto existing leaf item. # mistake, change this: if (Test-Path $frname -PathType Container) {$frname += '*'} # to: if (Test-Path $toname -PathType Container) {$frname += '*'} -- Kiron |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Copy-Item : Container cannot be copied onto existing leaf item Thanks for your help! "Kiron" wrote: Quote: > # mistake, change this: > if (Test-Path $frname -PathType Container) {$frname += '*'} > > # to: > if (Test-Path $toname -PathType Container) {$frname += '*'} > > -- > Kiron > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| rename-item, move-item and special chars. | PowerShell | |||
| -container in Copy-Item | PowerShell | |||
| copy-item changing files attributes on network copy failures | PowerShell | |||
| Copy-Item not honoring -container | PowerShell | |||
| Copy-Item not honoring -container | PowerShell | |||