X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Ffile%2FIOHelper.java;h=5b4e634656fcb649dbc40952292c7a1c90762a76;hb=30d5a74b04947e845e4b8f4ae3220452d5b1de2c;hp=a6dd05f6abf99aa3d366bc8fbe7db328ea7d0ce2;hpb=f2f5769996256492b3cd430a4c57b1317582b340;p=svjatoslav_commons.git diff --git a/src/main/java/eu/svjatoslav/commons/file/IOHelper.java b/src/main/java/eu/svjatoslav/commons/file/IOHelper.java index a6dd05f..5b4e634 100644 --- a/src/main/java/eu/svjatoslav/commons/file/IOHelper.java +++ b/src/main/java/eu/svjatoslav/commons/file/IOHelper.java @@ -17,6 +17,28 @@ import java.io.IOException; public class IOHelper { + /** + * Deletes files and directories recursively. WARNING!!! Follows symlinks!!! + */ + public static void deleteRecursively(final File file) throws IOException { + if (file.isDirectory()) { + + for (final File subFile : file.listFiles()) + deleteRecursively(subFile); + + if (!file.delete()) + throw new FileNotFoundException("Failed to delete directory: " + + file); + + return; + } + + if (file.isFile()) + if (!file.delete()) + throw new FileNotFoundException("Failed to delete file: " + + file); + } + public static byte[] getFileContents(final File file) throws FileNotFoundException, IOException {