Java File Path Delete deleteDir(File directory)

Here you can find the source of deleteDir(File directory)

Description

Delete the directory associated with the File as path if empty

License

Open Source License

Parameter

Parameter Description
directory a parameter

Return

True if deleted, False else.

Declaration

public final static boolean deleteDir(File directory) 

Method Source Code

//package com.java2s;
/**// ww  w. j  a va  2 s . co  m
 * This file is part of Waarp Project.
 * 
 * Copyright 2009, Frederic Bregier, and individual contributors by the @author tags. See the
 * COPYRIGHT.txt in the distribution for a full listing of individual contributors.
 * 
 * All Waarp Project 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 3 of
 * the License, or (at your option) any later version.
 * 
 * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with Waarp . If not, see
 * <http://www.gnu.org/licenses/>.
 */

import java.io.File;

public class Main {
    /**
     * Delete the directory associated with the File as path if empty
     * 
     * @param directory
     * @return True if deleted, False else.
     */
    public final static boolean deleteDir(File directory) {
        if (directory == null) {
            return true;
        }
        if (!directory.exists()) {
            return true;
        }
        if (!directory.isDirectory()) {
            return false;
        }
        return directory.delete();
    }

    /**
     * Delete physically the file
     * 
     * @param file
     * @return True if OK, else if not (or if the file never exists).
     */
    public final static boolean delete(File file) {
        if (!file.exists()) {
            return true;
        }
        return file.delete();
    }
}

Related

  1. deleteDir(File dir, boolean deleteSelf)
  2. deleteDir(File dir, int depth, boolean deleteRootDirectory)
  3. deleteDir(File dir, String dirPath)
  4. deleteDir(File directory)
  5. deleteDir(File directory)
  6. deleteDir(File directory)
  7. deleteDir(File directory, boolean removeAll)
  8. deleteDir(File dirFile)
  9. deleteDir(File dirPath)