Here you can find the source of removeDirectories(File file, String regex)
Parameter | Description |
---|---|
file | a parameter |
regex | a parameter |
public static boolean removeDirectories(File file, String regex)
//package com.java2s; import java.io.File; public class Main { /**/*from w w w. j av a2 s . c o 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; } }