diff options
author | James Moger <james.moger@gitblit.com> | 2013-09-30 08:10:24 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2013-09-30 10:10:47 -0400 |
commit | 73d8e161834f768bc772e38a7ebf1a140962c685 (patch) | |
tree | e97bb98137eeb59023fd1db422b411267dc5c35b /src | |
parent | ed9717d4e8d36bdc37a48bb0bdf8a000a1362127 (diff) | |
download | gitblit-73d8e161834f768bc772e38a7ebf1a140962c685.tar.gz gitblit-73d8e161834f768bc772e38a7ebf1a140962c685.zip |
Add recursive delete function to FileUtils
Change-Id: Ie177a9e5e9f88ea35bb8f9fe0b6c9af7ce92a280
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/gitblit/utils/FileUtils.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main/java/com/gitblit/utils/FileUtils.java b/src/main/java/com/gitblit/utils/FileUtils.java index fb3e09ce..f3a25987 100644 --- a/src/main/java/com/gitblit/utils/FileUtils.java +++ b/src/main/java/com/gitblit/utils/FileUtils.java @@ -216,6 +216,30 @@ public class FileUtils { }
/**
+ * Delete a file or recursively delete a folder.
+ *
+ * @param fileOrFolder
+ * @return true, if successful
+ */
+ public static boolean delete(File fileOrFolder) {
+ boolean success = false;
+ if (fileOrFolder.isDirectory()) {
+ File [] files = fileOrFolder.listFiles();
+ if (files != null) {
+ for (File file : files) {
+ if (file.isDirectory()) {
+ success |= delete(file);
+ } else {
+ success |= file.delete();
+ }
+ }
+ }
+ }
+ success |= fileOrFolder.delete();
+ return success;
+ }
+
+ /**
* Copies a file or folder (recursively) to a destination folder.
*
* @param destinationFolder
|