Message203283
Shutil supports deleting of files and directories but it offers no way to delete directory content (without deleting directory itself). Shell programming includes a lot of "rm -rf /dir" and "rm -f /dir/*", and there is no direct equivalent of these commands in Python. Educate me if I am wrong on this claim.
Sure, I can write a quick for loop, and delete each subfile and subdirectory manually, but adding such ability to shutil would greatly enhance readability and simplicity of Python file handling scripts.
Implementation could be as simply as :
import os
for root, dirs, files in os.walk(top, topdown=False):
for name in files:
os.remove(os.path.join(root, name))
for name in dirs:
os.rmdir(os.path.join(root, name))
(example taken from http://docs.python.org/2/library/os.html#os.walk) |
|
Date |
User |
Action |
Args |
2013-11-18 11:45:26 | ivan.radic | set | recipients:
+ ivan.radic |
2013-11-18 11:45:26 | ivan.radic | set | messageid: <1384775126.27.0.181995142425.issue19642@psf.upfronthosting.co.za> |
2013-11-18 11:45:26 | ivan.radic | link | issue19642 messages |
2013-11-18 11:45:25 | ivan.radic | create | |
|