Java Delete Directory deleteDirectory(String dirName)

Here you can find the source of deleteDirectory(String dirName)

Description

Recursively deletes a directory

License

Open Source License

Parameter

Parameter Description
dirName the path of the directory

Declaration

public static void deleteDirectory(String dirName) 

Method Source Code

//package com.java2s;
/*==========================================================================*\
 |  $Id: FileUtilities.java,v 1.5 2014/06/16 15:59:40 stedwar2 Exp $
 |*-------------------------------------------------------------------------*|
 |  Copyright (C) 2006-2012 Virginia Tech
 |
 |  This file is part of Web-CAT.//from w w w. j a  v a 2 s. c  o m
 |
 |  Web-CAT is free software; you can redistribute it and/or modify
 |  it under the terms of the GNU Affero General Public License as published
 |  by the Free Software Foundation; either version 3 of the License, or
 |  (at your option) any later version.
 |
 |  Web-CAT 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 Affero General Public License
 |  along with Web-CAT; if not, see <http://www.gnu.org/licenses/>.
\*==========================================================================*/

import java.io.File;

public class Main {
    /**
     * Recursively deletes a directory
     *
     * @param dirName the path of the directory
     */
    public static void deleteDirectory(String dirName) {
        deleteDirectory(new File(dirName));
    }

    /**
     * Recursively deletes a directory
     *
     * @param dir the File object for the directory
     */
    public static void deleteDirectory(File dir) {
        File[] files = dir.listFiles();
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                deleteDirectory(files[i]);
            }
            files[i].delete();
        }
        dir.delete();
    }
}

Related

  1. deleteDirectory(String directory)
  2. deleteDirectory(String directory)
  3. deleteDirectory(String directoryName)
  4. deleteDirectory(String directoryName)
  5. deleteDirectory(String dirName)
  6. deleteDirectory(String dirname, boolean recursive)
  7. deleteDirectory(String fileName)
  8. deleteDirectory(String folder)
  9. deleteDirectory(String name)