From: Fraxinas Date: Wed, 29 Jul 2009 08:12:31 +0000 (+0200) Subject: add getSize convenience function to obtain file or directory size (not tested with... X-Git-Tag: 2.6.0~172^2~3 X-Git-Url: https://git.cweiske.de/enigma2.git/commitdiff_plain/eded0db3bc821a1633da2fd33cf0019407dd1089?ds=sidebyside add getSize convenience function to obtain file or directory size (not tested with directories containing lots of files) --- diff --git a/lib/python/Tools/Directories.py b/lib/python/Tools/Directories.py index f9394978..aaa2a9da 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