Here you can find the source of deleleFiles(String regex, String path)
public static int deleleFiles(String regex, String path)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { public static int deleleFiles(String regex, String path) { int rtn = 0; if (path != null && regex != null) { File folder = new File(path); File[] files = folder.listFiles(); for (int i = 0; i < files.length; i++) { String fname = files[i].getName(); if (fname.matches(regex)) { if (files[i].delete()) { rtn++;//from w w w . ja v a 2 s. c om } } } } return rtn; } public static int deleleFiles(String regex) { return deleleFiles(regex, "."); } }