Here you can find the source of deleteFiles(File file)
public static boolean deleteFiles(File file)
//package com.java2s; import java.io.File; public class Main { public static boolean deleteFiles(File file) { return deleteFiles(file, ".*"); }//from w w w. j a v a 2s.c om /** * 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; } }