add getSize convenience function to obtain file or directory size (not tested with...
authorFraxinas <andreas.frisch@multimedia-labs.de>
Wed, 29 Jul 2009 08:12:31 +0000 (10:12 +0200)
committerFraxinas <andreas.frisch@multimedia-labs.de>
Wed, 29 Jul 2009 08:12:31 +0000 (10:12 +0200)
lib/python/Tools/Directories.py

index f939497..aaa2a9d 100755 (executable)
@@ -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!"
                        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