Removing hidden files and folders with python ...


K

Konrad Mühler

Hi,

I try to delete a whole directory-tree using shutil.rmtree(...)
But there are always the hidden files and folders (e.g. from the svn
..svn) left.

How can I delete -all- files and folders (also the hidden) with python?

Many Thanks
Konrad
 
Ad

Advertisements

G

Gabriel Genellina

I try to delete a whole directory-tree using shutil.rmtree(...)
But there are always the hidden files and folders (e.g. from the svn
.svn) left.

How can I delete -all- files and folders (also the hidden) with python?

I assume you use Windows.
You have to reset the "readonly", "system" and "hidden" directory
attributes. os.chmod can reset the first one, but for the others you
have to use ctypes or the pywin32 package to call the
SetFileAttributes function.
Of course there is system too:
os.system("attrib -r -h -s filename")

You could use rmtree once, apply the above on the remaining files and
directories -if any- and try rmtree again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top