From 417c14a02338d10a34fdf4875761c9e4a92aef1c Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 12 Mar 2020 18:18:59 -0700 Subject: [PATCH] Let directories @size property work also. I was hesitant at first because of course it can be slow to run, but previously you'd have to have an if so that you know whether you've got int or none corresponding to files and folders anyway, so I don't think the caller-side complexity is increased at all, and saves me from having to write this as a helper function outside the class. Only for special cases like preparing to handle permissionerror would you need to use your own function. --- voussoirkit/pathclass.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/voussoirkit/pathclass.py b/voussoirkit/pathclass.py index 5f55905..3209794 100644 --- a/voussoirkit/pathclass.py +++ b/voussoirkit/pathclass.py @@ -236,7 +236,7 @@ class Path: if self.is_file: return os.path.getsize(self.absolute_path) else: - return None + return sum(file.size for file in self.walk() if file.is_file) def spawn(self, path): return self.__class__(path, force_sep=self.force_sep)