[Tutor] shutil.rmtree clarification

Garry Willgoose Garry.Willgoose at newcastle.edu.au
Thu May 17 15:32:29 CEST 2012

I'm trying to remove a directory that has within it a directory tree structure and files and thought the following would work (the online docs seem to suggest it will remove the underlying directory tree and included files)


but I got back an error (Python 2.7 on OSX)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/shutil.py", line 253, in rmtree
    onerror(os.rmdir, path, sys.exc_info())
  File "/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/shutil.py", line 251, in rmtree
OSError: [Errno 66] Directory not empty: 'test_directory'

which seems to suggest that the directory has to be empty to work ... sort of defeats the purpose of wanting to removing the tree in one command. What do people suggest short of calling os.system('rm -R test_directory').

Prof Garry Willgoose
Australian Professorial Fellow,
School of Engineering,
The University of Newcastle,
Callaghan, NSW, 2308.

Phone: +61 2 4921 6050 (Tues-Thurs)
             +61 2 6545 9574 (Fri-Mon)
FAX: +61 2 4921 6991
garry.willgoose at newcastle.edu.au
g.willgoose at telluricresearch.com

More information about the Tutor mailing list