![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #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 | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can the copy-item cmdlet be used to copy public folders to C: ? | JoshGfromPortland | PowerShell | 8 | 06-09-2008 09:03 PM |
| copy-item changing files attributes on network copy failures | jas | PowerShell | 4 | 01-31-2008 12:39 PM |
| Getting Copy-Item to display messages (like the old COPY command in CMD.EXE) ?? | Marc Scheuner | PowerShell | 15 | 10-26-2007 02:41 AM |
| Copy-Item | VRSki | PowerShell | 4 | 08-13-2007 10:38 AM |
| Copy-Item or Copy-ItemProperty and Remote Registry. | Brandon Shell | PowerShell | 1 | 01-09-2007 10:51 AM |