I have around 500 text files inside a directory with a same prefix in their filename say dailyReport_.
dailyReport_
The latter part of the file is the date of the fi
Use FileFilter like so:
FileFilter
File dir = new File(); File[] toBeDeleted = dir.listFiles(new FileFilter() { boolean accept(File pathname) { return (pathname.getName().startsWith("dailyReport_08") && pathname.getName().endsWith(".txt")); } for (File f : toBeDeleted) { f.delete(); }