Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - bug in copy-item of readonly files

Reply
 
Old 12-20-2008   #1 (permalink)
Leo Tohill


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46