Here you can find the source of removeDirectories(File file)
Parameter | Description |
---|---|
file | a parameter |
public static boolean removeDirectories(File file)
//package com.java2s; import java.io.File; public class Main { /**//from w w w . j a va 2 s. co m * recursively remove directory and all sub directories * @param file * @return */ public static boolean removeDirectories(File file) { if (!file.exists()) return true; // recursively traversal all sub files if (file.isDirectory()) { File[] subFiles = file.listFiles(); for (File subFile : subFiles) { if (!removeDirectories(subFile)) return false; } } // it is file or it is empty return file.delete(); } /** * recursively remove directory and all sub directories which matches * regular expression * @param file * @param regex * @return */ public static boolean removeDirectories(File file, String regex) { if (!file.exists()) return true; // recursively traversal all sub files if (file.isDirectory()) { if (file.getName().matches(regex)) { if (!removeDirectories(file)) return false; } else { File[] subFiles = file.listFiles(); for (File subFile : subFiles) { if (!removeDirectories(subFile, regex)) return false; } } } return true; } }