Java tutorial
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FilenameFilter; public class Main { public static boolean deleteFiles(final File directory, final String prefix) { for (File child : directory.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.startsWith(prefix); } })) { deleteRecursive(child); } return true; } public static boolean deleteRecursive(File fileOrDirectory) { if (fileOrDirectory.isDirectory()) { for (File child : fileOrDirectory.listFiles()) { deleteRecursive(child); } } return fileOrDirectory.delete() || !fileOrDirectory.exists(); } }