Java Delete Tree delTree(File file)

Here you can find the source of delTree(File file)

Description

Delete either the supplied file or all files within the directory supplied or any sub-directories.

License

Open Source License

Parameter

Parameter Description
file file or directory to delete

Return

ok

Declaration

public static boolean delTree(File file) 

Method Source Code

//package com.java2s;
/**// w  w  w.  ja v  a 2 s .c om
 * Appframework
 * Copyright (C) 2003-2016 SSHTOOLS Limited
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 */

import java.io.File;

public class Main {
    /**
     * Delete either the supplied file or all <strong>files</strong> within the 
     * directory supplied or any sub-directories. Directories will <strong>not</strong>
     * be deleted.  
     * 
     * @param file file or directory to delete
     * @return ok
     */
    public static boolean delTree(File file) {
        if (file.isFile()) {
            return file.delete();
        }
        File[] list = file.listFiles();
        for (int i = 0; i < list.length; i++) {
            if (!delTree(list[i])) {
                return false;
            }
        }
        return true;
    }
}

Related

  1. delTree(File dir)
  2. delTree(File dir, boolean deleteDirItSelf)
  3. delTree(File directory)
  4. deltree(File directory)
  5. delTree(File f)
  6. delTree(File file)
  7. delTree(File file)
  8. delTree(File file)
  9. delTree(File file)