Amresh,
 
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. 
 
Is there a better way to do it?  Would appreciate feedback on the code below.
 
import shutil
import os
 
def zaps(self):
     
        try:
            shutil.rmtree('f:/m2m')
            
                               
        except OSError, inst:
            print OSError
            os.chmod(inst.filename, 0666)
            self.zaps()
 
Regards,
 
John.
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Amresh Kulkarni
Sent: 16 June 2006 16:27
To: tutor@python.org
Subject: [Tutor] Delete directories recursively

Hi,

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.
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?

--
~~AMRESH~~
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to