[Tutor] Delete directories recursively
John Corry
john.corry at ntlworld.com
Fri Jun 16 19:55:56 CEST 2006
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: tutor-bounces at python.org [mailto:tutor-bounces at python.org]On Behalf
Of Amresh Kulkarni
Sent: 16 June 2006 16:27
To: tutor at 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~~
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060616/ee8a0842/attachment.htm
More information about the Tutor
mailing list