]> source.dussan.org Git - gitblit.git/commitdiff
Add recursive delete function to FileUtils
authorJames Moger <james.moger@gitblit.com>
Mon, 30 Sep 2013 12:10:24 +0000 (08:10 -0400)
committerJames Moger <james.moger@gitblit.com>
Mon, 30 Sep 2013 14:10:47 +0000 (10:10 -0400)
Change-Id: Ie177a9e5e9f88ea35bb8f9fe0b6c9af7ce92a280

src/main/java/com/gitblit/utils/FileUtils.java

index fb3e09ce6278da37c79d77299cd9304c93bb9686..f3a2598720260e36358ae1b734d28f648132645f 100644 (file)
@@ -215,6 +215,30 @@ public class FileUtils {
                return 0;\r
        }\r
 \r
+       /**\r
+        * Delete a file or recursively delete a folder.\r
+        *\r
+        * @param fileOrFolder\r
+        * @return true, if successful\r
+        */\r
+       public static boolean delete(File fileOrFolder) {\r
+               boolean success = false;\r
+               if (fileOrFolder.isDirectory()) {\r
+                       File [] files = fileOrFolder.listFiles();\r
+                       if (files != null) {\r
+                               for (File file : files) {\r
+                                       if (file.isDirectory()) {\r
+                                               success |= delete(file);\r
+                                       } else {\r
+                                               success |= file.delete();\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               success |= fileOrFolder.delete();\r
+               return success;\r
+       }\r
+\r
        /**\r
         * Copies a file or folder (recursively) to a destination folder.\r
         * \r