Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shutil.rmtree() clarification

I have read the documentation for this function, however, I dont think I understand it properly. If anyone can tell me what I'm missing, or if I am correct, it would be a great help. Here is my understanding:

using the shutil.rmtree(path) function, it will delete only the directory specified, not the entire path. IE:

shutil.rmtree('user/tester/noob')

using this, it would only delete the 'noob' directory correct? not the complete path?

like image 538
IT Ninja Avatar asked Jun 03 '12 19:06

IT Ninja


2 Answers

If noob is a directory, the shutil.rmtree() function will delete noob and all files and subdirectories below it. That is, noob is the root of the tree to be removed.

like image 110
Rich Walsh Avatar answered Nov 06 '22 20:11

Rich Walsh


This will definitely only delete the last directory in the specified path. Just try it out:

mkdir -p foo/bar
python
import shutil
shutil.rmtree('foo/bar')

...will only remove 'bar'.

like image 32
krase Avatar answered Nov 06 '22 18:11

krase