Java Delete Empty Directory deleteEmptyFolders(java.io.File file)

Here you can find the source of deleteEmptyFolders(java.io.File file)

Description

delete Empty Folders

License

Open Source License

Declaration

public static boolean deleteEmptyFolders(java.io.File file) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007 Red Hat, Inc./*from w ww  .j a  va  2 s.  co  m*/
 * Distributed under license by Red Hat, Inc. All rights reserved.
 * This program is 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:
 *     Red Hat, Inc. - initial API and implementation
 ******************************************************************************/

public class Main {
    public static boolean deleteEmptyFolders(java.io.File file) {
        boolean b = true;
        if (file.isDirectory()) {
            java.io.File[] children = file.listFiles();
            for (int i = 0; i < children.length; i++)
                b &= deleteEmptyFolders(children[i]);
            if (file.listFiles().length == 0)
                file.delete();
        }
        return b;
    }
}

Related

  1. deleteEmptyDirectoryRecursive(File directory)
  2. deleteEmptyDirectoryRecursive(File directory)
  3. deleteEmptyDirs(File dir)
  4. deleteEmptyDirs(File dir)
  5. deleteEmptyFiles(String p)
  6. deleteEmptyFolders(String[] args)
  7. deleteEmptyParentFolders(File leafFolder)
  8. deleteEmptyParents(File currentParentFile, String inputDir)