Suggestion: Add shutil.get_dir_size
Hi, I have a suggestion: Add a function shutil.get_dir_size that gets the size of a directory, including all the items inside it recursively. I currently need this functionality and it looks like I'll have to write my own function for it. Cheers, Ram.
On 02May2017 22:07, Ram Rachum
I have a suggestion: Add a function shutil.get_dir_size that gets the size of a directory, including all the items inside it recursively. I currently need this functionality and it looks like I'll have to write my own function for it.
Feels like a rather niche function. Had you considered just calling "du" via
subprocess and reading the number it returns?
Cheers,
Cameron Simpson
Calling `du` is possible but I prefer to avoid these kinds of solutions.
(OS-specific, parsing text output from a third-party program.)
On Wed, May 3, 2017 at 1:57 AM, Cameron Simpson
On 02May2017 22:07, Ram Rachum
wrote: I have a suggestion: Add a function shutil.get_dir_size that gets the size of a directory, including all the items inside it recursively. I currently need this functionality and it looks like I'll have to write my own function for it.
Feels like a rather niche function. Had you considered just calling "du" via subprocess and reading the number it returns?
Cheers, Cameron Simpson
On 03May2017 09:13, Ram Rachum
Calling `du` is possible but I prefer to avoid these kinds of solutions. (OS-specific, parsing text output from a third-party program.)
Your choice, and fair enough.
However I'd point out that "du" is available on all UNIX systems (includes
MacOS) and UNIXlike systems (Linux in its many forms), and has the advantage
that it embodies all the platform specific knowledge you need as alluded to in
another reply; hard links, block counts things-not-plain-files and so forth.
Of course, I speak here with some hypocracy because I'm the kind of person
who'd write his own for things like this sometimes also. Starting with Python's
os.walk function would get you off the ground.
If you end up with something clean and usable by others, publish it to PyPI.
Cheers,
Cameron Simpson
On 02.05.17 22:07, Ram Rachum wrote:
I have a suggestion: Add a function shutil.get_dir_size that gets the size of a directory, including all the items inside it recursively. I currently need this functionality and it looks like I'll have to write my own function for it.
The comprehensive implementation should take into account hard links, mount points, variable block sizes, sparse files, transparent files and blocks compression, file tails packing, blocks deduplication, additional file streams, file versioning, and many many other FS specific features. If you implement a module providing this feature, publish it on PyPI and prove its usefulness for common Python user, it may be considered for inclusion in the Python standard library.
On 3 May 2017 at 06:43, Serhiy Storchaka
On 02.05.17 22:07, Ram Rachum wrote:
I have a suggestion: Add a function shutil.get_dir_size that gets the size of a directory, including all the items inside it recursively. I currently need this functionality and it looks like I'll have to write my own function for it.
The comprehensive implementation should take into account hard links, mount points, variable block sizes, sparse files, transparent files and blocks compression, file tails packing, blocks deduplication, additional file streams, file versioning, and many many other FS specific features. If you implement a module providing this feature, publish it on PyPI and prove its usefulness for common Python user, it may be considered for inclusion in the Python standard library.
+1 I would be interested in a pure-Python version of "du", but would expect to see it as a 3rd party module in the first instance (at least until all of the bugs have been thrashed out) rather than being immediately proposed for the stdlib. Paul
participants (4)
-
Cameron Simpson
-
Paul Moore
-
Ram Rachum
-
Serhiy Storchaka