Discussion:
shutil.rmtree raises "OSError: [Errno 39] Directory not empty" exception
(too old to reply)
Tim Chase
16 years ago
Permalink
shutil.rmtree(filename)
File "/usr/lib64/python2.5/shutil.py", line 178, in rmtree
onerror(os.rmdir, path, sys.exc_info())
File "/usr/lib64/python2.5/shutil.py", line 176, in rmtree
os.rmdir(path)
OSError: [Errno 39] Directory not empty: /path/to/my/dir
According to the documentation, shutil.rmtree should not care about
directory being not empty.
This sounds suspiciously like a permission issue. rmtree()
*should* walk the tree removing items *if it can*. If a file
can't be deleted, it treats it as an error. rmtree() takes
parameters for ignore_errors and an onerror callback function, so
you can catch these error conditions.

-tkc
Sean DiZazzo
16 years ago
Permalink
...
This one took me a long time to find a solution for. Check this page,
and see comment #3: http://code.activestate.com/recipes/193736/

I guess if the file is marked as "Read Only" or "Archive", or
whatever, it cannot be deleted with shutil.rmtree()

The key: win32api.SetFileAttributes(path,
win32con.FILE_ATTRIBUTE_NORMAL)

It will work!

~Sean

Loading...