![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| Guest | Copy-Item How do I prevent Copy-Item from overwriting an exsisting file |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Copy-Item "JW" <JW@discussions.microsoft.com> wrote in message news:3EAB4623-137F-41AD-A4E1-1576431544D5@microsoft.com... > How do I prevent Copy-Item from overwriting an exsisting file It shouldn't do that by default unless you specify the -force parameter. -- Keith |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Copy-Item Well on my system it does. According to the documentation the -force switch only: "Allows cmdlet to override restrictions such as renaming existing files as long as security is not compromised" Which is in my opinion needed when attributes like 'hidden' etc. are specified. The command: Copy-Item C:\test.txt -Destination C:\test\ happily copies test.txt into the C:\test directory clobbering the exsisting test.txt already present in C:\test -- JW "Keith Hill" wrote: > "JW" <JW@discussions.microsoft.com> wrote in message > news:3EAB4623-137F-41AD-A4E1-1576431544D5@microsoft.com... > > How do I prevent Copy-Item from overwriting an exsisting file > > It shouldn't do that by default unless you specify the -force parameter. > > -- > Keith > |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Copy-Item "JW" <JW@discussions.microsoft.com> wrote in message news:530C457C-4110-44CC-A556-F1B7B045E2B9@microsoft.com... > Well on my system it does. According to the documentation the -force > switch > only: > > "Allows cmdlet to override restrictions such as renaming existing files as > long as security is not compromised" > > Which is in my opinion needed when attributes like 'hidden' etc. are > specified. > > The command: > > Copy-Item C:\test.txt -Destination C:\test\ > > happily copies test.txt into the C:\test directory clobbering the > exsisting > test.txt already present in C:\test Yeah I see the same behavior. It is Move-Item that requires -force to overwrite a file. Seems a bit inconsistent that Copy-Item doesn't behave the same way IMO. -- Keith |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: Copy-Item Here is a quick little function I just made for a work around. If you dot source it you can use it when ever you need it. function SafeCopy { param ([string]$destination = $(throw "Please specify a destination"), $confirm = $true) Process { $fulldestination = (Get-Item $destination).FullName + '\' + $_.Name if (Test-Path $fulldestination) { if ($confirm) { Write-Warning "File exists" Copy-Item $_.FullName $fulldestination -confirm } } else {Copy-Item $_.FullName $fulldestination} } } I made it to work in the pipeline so that I didn't have support all the switches that Copy-Item does. Just use it like this: PS> Get-ChildItem test.txt | SafeCopy c:\temp $false That way you can use all the switches of Get-ChildItem and even pass it to Where for further filtering before actually doing your copy. -= IJuan =- "JW" wrote: > Well on my system it does. According to the documentation the -force switch > only: > > "Allows cmdlet to override restrictions such as renaming existing files as > long as security is not compromised" > > Which is in my opinion needed when attributes like 'hidden' etc. are > specified. > > The command: > > Copy-Item C:\test.txt -Destination C:\test\ > > happily copies test.txt into the C:\test directory clobbering the exsisting > test.txt already present in C:\test > > -- > JW > > > "Keith Hill" wrote: > > > "JW" <JW@discussions.microsoft.com> wrote in message > > news:3EAB4623-137F-41AD-A4E1-1576431544D5@microsoft.com... > > > How do I prevent Copy-Item from overwriting an exsisting file > > > > It shouldn't do that by default unless you specify the -force parameter. > > > > -- > > Keith > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Copy-Item : Container cannot be copied onto existing leaf item. | PowerShell | |||
| Can the copy-item cmdlet be used to copy public folders to C: ? | PowerShell | |||
| copy-item changing files attributes on network copy failures | PowerShell | |||
| Getting Copy-Item to display messages (like the old COPY command in CMD.EXE) ?? | PowerShell | |||
| Copy-Item or Copy-ItemProperty and Remote Registry. | PowerShell | |||