Java File Path Delete deleteDirectory(final String fullDirPath)

Here you can find the source of deleteDirectory(final String fullDirPath)

Description

delete Directory

License

Open Source License

Declaration

static public boolean deleteDirectory(final String fullDirPath) 

Method Source Code

//package com.java2s;
/******************************************************************************
 *
 * CoreWall / Corelyzer - An Initial Core Description Tool
 * Copyright (C) 2004 - 2007 Arun Gangadhar Gudur Rao, Julian Yu-Chung Chen
 * Electronic Visualization Laboratory, University of Illinois at Chicago
 *
 * This software is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either Version 2.1 of the License, or
 * (at your option) any later version./*  www  . j  a v a 2  s  . c  o m*/
 *
 * This software 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 Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser Public License along
 * with this software; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * Questions or comments about CoreWall should be directed to
 * cavern@evl.uic.edu
 *
 *****************************************************************************/

import java.io.File;

public class Main {
    static public boolean deleteDirectory(final String fullDirPath) {
        String sp = System.getProperty("file.separator");
        File texDir = new File(fullDirPath);

        if (texDir.exists() && texDir.isDirectory()) {
            String[] dirList = texDir.list();

            for (String aDirList : dirList) {
                String myDirPath = texDir.getAbsolutePath() + sp + aDirList;
                File d = new File(myDirPath);

                if (d.exists() && d.isDirectory()) {
                    System.out.print("Delete " + d.getAbsolutePath());
                    boolean isSuccess = deleteDir(d);
                    String result = isSuccess ? "SUCCESS" : "FAILED";
                    System.out.print(" : " + result + "\n");
                }
            }

            texDir.delete();
        }

        return false;
    }

    static public boolean deleteDir(final File dir) {
        if (dir.isDirectory()) {
            String[] children = dir.list();
            for (String aChildren : children) {
                boolean success = deleteDir(new File(dir, aChildren));
                if (!success) {
                    return false;
                }
            }
        }

        // The directory is now empty so delete it
        return dir.delete();
    }
}

Related

  1. deleteDirectory(File path, boolean deleteMyself, boolean deleteHidden)
  2. deleteDirectory(File path, boolean includeDir)
  3. deleteDirectory(final File path)
  4. deleteDirectory(final File path)
  5. deleteDirectory(final String directoryPath)
  6. deleteDirectory(final String path)
  7. deleteDirectory(String dir_path)
  8. deleteDirectory(String directoryPath)
  9. DeleteDirectory(String directoryPath)