[issue19642] shutil to support equivalent of: rm -f /dir/*
Changes by Barry A. Warsaw ba...@python.org: -- nosy: +barry ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19642 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19642] shutil to support equivalent of: rm -f /dir/*
Serhiy Storchaka added the comment: Rather like this: for n in os.listdir(dirpath): p = os.path.join(dirpath, n) if os.path.isdir(p): shutil.rmtree(p) else: os.unlink(p) -- nosy: +serhiy.storchaka ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19642 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19642] shutil to support equivalent of: rm -f /dir/*
Antoine Pitrou added the comment: rm -rf /dir Isn't it shutil.rmtree()? Am I missing something? rm -f /dir/* So it should skip dotted files, or remove them? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19642 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19642] shutil to support equivalent of: rm -f /dir/*
Changes by Berker Peksag berker.pek...@gmail.com: -- stage: - needs patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19642 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19642] shutil to support equivalent of: rm -f /dir/*
Changes by Éric Araujo mer...@netwok.org: -- nosy: +eric.araujo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19642 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19642] shutil to support equivalent of: rm -f /dir/*
New submission from Ivan Radic: 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) -- components: IO messages: 203283 nosy: ivan.radic priority: normal severity: normal status: open title: shutil to support equivalent of: rm -f /dir/* type: enhancement versions: Python 2.7, Python 3.5 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19642 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19642] shutil to support equivalent of: rm -f /dir/*
Changes by Serhiy Storchaka storch...@gmail.com: -- nosy: +hynek, tarek versions: -Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19642 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19642] shutil to support equivalent of: rm -f /dir/*
R. David Murray added the comment: See also issue 13229. You can replicate 'rm -f' like this: for p in glob.glob('/dir/*'): os.remove(p) That doesn't seem worth an extra function. The annoying one to emulate is 'rm -rf /dir/*', because with the current shutil tools you have to make different calls depending on whether the object is a file or a directory. Pathlib doesn't help with that (it has no generic 'remove' method that applies to both directories and files), but it does make the iteration easier. -- components: +Library (Lib) -IO nosy: +pitrou, r.david.murray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19642 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com