Java File Path Delete deleteDirectory(File path, boolean deleteMyself, boolean deleteHidden)

Here you can find the source of deleteDirectory(File path, boolean deleteMyself, boolean deleteHidden)

Description

delete Directory

License

Open Source License

Declaration

public static void deleteDirectory(File path, boolean deleteMyself, boolean deleteHidden) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006-2012//  w w w  .j ava  2  s . c  o  m
 * Software Technology Group, Dresden University of Technology
 * DevBoost GmbH, Berlin, Amtsgericht Charlottenburg, HRB 140026
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *   Software Technology Group - TU Dresden, Germany;
 *   DevBoost GmbH - Berlin, Germany
 *      - initial API and implementation
 ******************************************************************************/

import java.io.File;

public class Main {
    public static void deleteDirectory(File path, boolean deleteMyself, boolean deleteHidden) {
        if (path.exists()) {
            File[] files = path.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (deleteHidden || !files[i].getName().startsWith(".")) {
                    if (files[i].isDirectory()) {
                        deleteDirectory(files[i], true, deleteHidden);
                    } else {
                        files[i].delete();
                    }
                }
            }
        }
        if (deleteMyself) {
            path.delete();
        }
    }
}

Related

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