<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1528" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=930484917-16062006>Amresh,</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=930484917-16062006></SPAN></FONT></FONT></FONT> </DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=930484917-16062006>I had this problem a few months back. I
approached it backwards. Maybe not the right way to do it. I removed
all the files and directories and then had my exception handle the file if
it was read only. The exception handler changes the file from
read-only to not read only and then calls the function again.
</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=930484917-16062006></SPAN></FONT></FONT></FONT> </DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=930484917-16062006>Is there a better way to do it? Would appreciate
feedback on the code below.</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=930484917-16062006></SPAN></FONT></FONT></FONT> </DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=930484917-16062006>import shutil</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT><FONT><SPAN class=930484917-16062006></SPAN><FONT face=Arial><FONT
color=#0000ff><FONT size=2><SPAN class=930484917-16062006>import
os</SPAN></FONT></FONT></FONT></FONT></FONT></DIV>
<DIV><FONT><FONT><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=930484917-16062006></SPAN></FONT></FONT></FONT></FONT></FONT> </DIV>
<DIV><FONT><FONT><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=930484917-16062006></SPAN>def
zaps(self):<BR>
<BR>
try:<BR>
shutil.rmtree('f:/m2m')<BR> <BR> <BR>
except OSError,
inst:<BR>
print
OSError<BR>
os.chmod(inst.filename,
0666)<BR>
self.zaps()</FONT></FONT></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=930484917-16062006><FONT face=Arial color=#0000ff
size=2>Regards,</FONT></SPAN></DIV>
<DIV><SPAN class=930484917-16062006><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=930484917-16062006><FONT face=Arial color=#0000ff
size=2>John.</FONT></SPAN></DIV>
<BLOCKQUOTE>
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> tutor-bounces@python.org
[mailto:tutor-bounces@python.org]<B>On Behalf Of </B>Amresh
Kulkarni<BR><B>Sent:</B> 16 June 2006 16:27<BR><B>To:</B>
tutor@python.org<BR><B>Subject:</B> [Tutor] Delete directories
recursively<BR><BR></FONT></DIV>Hi,<BR><BR>I need to delete a directory and
its sub directories. However all dir's, sub dir;s and files have read only
access. How do i do this efficeintly using the os.walk command. <BR>I cannot
run this command on the dir as it gives me an error due to the read only
attribute. Is there any other way to do this? <BR clear=all><BR>--
<BR>~~AMRESH~~ </BLOCKQUOTE></BODY></HTML>