From eded0db3bc821a1633da2fd33cf0019407dd1089 Mon Sep 17 00:00:00 2001 From: Fraxinas Date: Wed, 29 Jul 2009 10:12:31 +0200 Subject: [PATCH] add getSize convenience function to obtain file or directory size (not tested with directories containing lots of files) --- lib/python/Tools/Directories.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/python/Tools/Directories.py b/lib/python/Tools/Directories.py index f939497..aaa2a9d 100755 --- a/lib/python/Tools/Directories.py +++ b/lib/python/Tools/Directories.py @@ -262,3 +262,14 @@ def copytree(src, dst, symlinks=False): utime(dst, (st.st_atime, st.st_mtime)) except: print "copy stats for", src, "failed!" + +def getSize(path, pattern=".*"): + path_size = 0 + if os_path.isdir(path): + files = crawlDirectory(path, pattern) + for file in files: + filepath = os_path.join(file[0], file[1]) + path_size += os_path.getsize(filepath) + elif os_path.isfile(path): + path_size = os_path.getsize(path) + return path_size -- 2.7.4