Java Utililty Methods Delete Directory

List of utility methods to do Delete Directory

Description

The list of methods to do Delete Directory are organized into topic(s).

Method

voiddeleteFiles(String directoryName)
Deletes the files in the directory, but does not remove the directory.
File dir = new File(directoryName);
File[] files = dir.listFiles();
for (int i = 0; i < files.length; i++) {
    files[i].delete();
voiddeleteFiles(String fileName)
delete Files
File oldPath = new File(fileName);
if (oldPath.isDirectory()) {
    File[] files = oldPath.listFiles();
    for (File file : files) {
        file.delete();
} else {
    oldPath.delete();
...
voiddeleteFiles(String root, String mask)
delete Files
deleteFiles(root, mask, false);
voiddeleteFiles(String sDir, String sSearch)
delete Files
File dir = new File(sDir).getCanonicalFile();
File[] files = dir.listFiles();
for (File f : files) {
    if (sSearch.equals("*")) {
        f.delete();
    } else {
        String[] sHold = sSearch.split(",");
        for (String s : sHold) {
...
voiddeleteFiles(String[] filenames)
Clean up - delete unzipped files that have already been included into ZIP
File file;
if (filenames == null)
    return;
for (int i = 0; i < filenames.length; i++) {
    file = new File(filenames[i]);
    if (file.exists())
        file.delete();
voiddeleteFilesAndDir(List files)
delete Files And Dir
File dir = files.get(0).getParentFile();
for (File file : files) {
    file.delete();
dir.delete();
voiddeleteFilesAndSubDirs(File dir)
delete Files And Sub Dirs
if (!dir.canRead())
    return;
for (File file : dir.listFiles()) {
    if (file.isFile()) {
        System.out.println("deleting " + file.getAbsolutePath());
        file.delete();
    } else {
        if (file.isDirectory() && (file.listFiles() == null || file.listFiles().length == 0)) {
...
booleandeleteFilesFromDirectory(final String dirNameIn, final String filePrefixIn)
Deletes all files in the directory but not the directory itself
boolean fileNotDeleted = false;
String filePrefix = filePrefixIn;
if (filePrefix != null) {
    filePrefix = filePrefix.toUpperCase();
File dir = new File(dirNameIn);
if (dir.isDirectory() == false) {
    throw new IllegalArgumentException("Specified path [" + dirNameIn + "] is not a directory");
...
voiddeleteFilesInDir(File dir)
Recursively deletes all the files of the specified directory.
deleteFilesInDir(dir, false);
voiddeleteFilesInDir(File dir)
delete Files In Dir
validateFile(dir, false, true, false, true);
for (File f : Arrays.asList(dir.listFiles()))
    if (!f.delete())
        throw new IOException("Unable to delete: " + f);