[Tutor] Delete directories recursively
Alan Gauld
alan.gauld at freenet.co.uk
Fri Jun 16 21:13:10 CEST 2006
> 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.
You can'ty since the reasoin the files are read-only is to prevent
them
being over-written or deleted! You need to convert them from read-only
and then delete them. Its not too hard provided you have the relevant
access rights to change mode.
> 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?
You can only do from Python what you can do from the OS.
If you don't have access to the files from the OS you won't have
access
from Python - thats why access rights are there!
For more on how to do it we need to know your OS, since this is
almost certainly a job for the OS rather than Python, unless you
want to do more than just delete the files.
If you do have access rights then you can find out all the needed
steps in the OS topic in my tutor.
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list