Here you can find the source of deleteFiles(File file, String regex)
Parameter | Description |
---|---|
file | a parameter |
regex | a parameter |
public static boolean deleteFiles(File file, String regex)
//package com.java2s; import java.io.File; public class Main { public static boolean deleteFiles(File file) { return deleteFiles(file, ".*"); }//from www . j a v a 2s .c o m /** * recursively delete all sub files which matches regular expression * @param file * @param regex * @return */ public static boolean deleteFiles(File file, String regex) { if (!file.exists()) return true; // recursively traversal all sub files if (file.isDirectory()) { File[] subFiles = file.listFiles(); for (File subFile : subFiles) { if (!deleteFiles(subFile, regex)) return false; } } else if (file.getName().matches(regex)) return file.delete(); return true; } }