![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | bug in copy-item of readonly files # this simple script illustrates a bug in copy-item involve -force and readonly files. # see comments below. # cleanup from previous runs and setup for this one. if (!(test-path c:\temp\t1 -pathtype container)) { new-item c:\temp\t1 -itemtype container } else { remove-item c:\temp\t1\* -force -recurse } if (!(test-path c:\temp\t2 -pathtype container)) { new-item c:\temp\t2 -itemtype container } else { remove-item c:\temp\t2\* -force -recurse } # Now create the test files and mark them readonly. out-file -filepath c:\temp\t1\item1.txt -input "item1" set-itemproperty c:\temp\t1\item1.txt -name attributes -value ReadOnly out-file -filepath c:\temp\t1\item2.txt -input "item2" set-itemproperty c:\temp\t1\item2.txt -name attributes -value ReadOnly # Now we have two files to copy. # The first time they will copy without incident. # The second time will complain of item1.txt already existing. It should not complain, due to -force. # It will also have removed the readonly attribute of the c:\temp\t2\item1.txt # The third time will complain of item2.txt already existing. # It will also have removed the readonly attribute if c:\temp\t2\item2.txt, and c:\temp\t2\item1.txt will be readonly again. # The fourth time will complain of item1.txt already existing, and will have removed the RO from c:\temp\t2\item1.txt # Now both destination files are NOT marked readonly, so a fifth execution succeeds without error. while ($true) { out-host -input "Copying files now..." copy-item c:\temp\t1\* c:\temp\t2 -recurse -force -erroraction silentlycontinue read-host -prompt "Press enter to copy again, else ctrl-c" } |
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 | |||