<!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>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN 
class=930484917-16062006>I had this problem a few months back.&nbsp; I 
approached it backwards.&nbsp; Maybe not the right way to do it.&nbsp; I removed 
all the files and directories and then&nbsp;had my exception handle the file if 
it was read only.&nbsp; The exception&nbsp; handler changes the file from 
read-only to not read only and then calls the function again.&nbsp; 
</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN 
class=930484917-16062006></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN 
class=930484917-16062006>Is there a better way to do it?&nbsp; 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>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT><FONT><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN 
class=930484917-16062006></SPAN>def 
zaps(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
try:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
shutil.rmtree('f:/m2m')<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
except OSError, 
inst:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
print 
OSError<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
os.chmod(inst.filename, 
0666)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.zaps()</FONT></FONT></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</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>&nbsp;</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>