From 73d8e161834f768bc772e38a7ebf1a140962c685 Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 30 Sep 2013 08:10:24 -0400 Subject: Add recursive delete function to FileUtils Change-Id: Ie177a9e5e9f88ea35bb8f9fe0b6c9af7ce92a280 --- src/main/java/com/gitblit/utils/FileUtils.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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 @@ -215,6 +215,30 @@ public class FileUtils { return 0; } + /** + * 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. * -- cgit v1.2.3