From a75a1819f4c7fa5080ddb47545fe9012a842e5b3 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Wed, 20 Jul 2011 21:08:57 -0400 Subject: [PATCH] Misc fixes. --- src/com/gitblit/utils/FileUtils.java | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) diff --git a/src/com/gitblit/utils/FileUtils.java b/src/com/gitblit/utils/FileUtils.java index 468b2a8..ce8cdf9 100644 --- a/src/com/gitblit/utils/FileUtils.java +++ b/src/com/gitblit/utils/FileUtils.java @@ -56,4 +56,28 @@ } return sb.toString(); } + + /** + * Recursively traverses a folder and its subfolders to calculate the total + * size in bytes. + * + * @param directory + * @return folder size in bytes + */ + public static long folderSize(File directory) { + if (directory == null || !directory.exists()) { + return -1; + } + if (directory.isFile()) { + return directory.length(); + } + long length = 0; + for (File file : directory.listFiles()) { + if (file.isFile()) + length += file.length(); + else + length += folderSize(file); + } + return length; + } } -- Gitblit v1.9.1