Java File Path Delete deleteDirectoryInternal(File path)

Here you can find the source of deleteDirectoryInternal(File path)

Description

delete Directory Internal

License

Open Source License

Declaration

static private boolean deleteDirectoryInternal(File path) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Copyright (c) 2005-2008 Whirlwind Match Limited. All rights reserved.
 *
 * This is open source software; you can use, redistribute and/or modify
 * it under the terms of the Open Software Licence v 3.0 as published by the 
 * Open Source Initiative.//w  ww .  j  a  v a  2s  . co  m
 *
 * You should have received a copy of the Open Software Licence along with this
 * application. if not, contact the Open Source Initiative (www.opensource.org)
 *****************************************************************************/

import java.io.File;

public class Main {
    static private boolean deleteDirectoryInternal(File path) {
        if (!path.exists()) {
            return true;
        }

        File[] files = path.listFiles();
        boolean succeeded = true;
        for (File file : files) {
            if (file.isDirectory()) {
                succeeded &= deleteDirectoryInternal(file);
            } else {
                succeeded &= file.delete();
            }
        }
        return succeeded && path.delete(); // Deliberately won't call path.delete() if !succeeded (it'll fail)
    }
}

Related

  1. deleteDirectoryAndContents(final File srcPath)
  2. deleteDirectoryAndContentsRecursive(final File srcPath, final boolean deleteSrcDir)
  3. deleteDirectoryContents(File path)
  4. deleteDirectoryContents(String directoryPath, boolean deleteChildDirectories)
  5. deleteDirectoryIncludeContent(String folderPath)
  6. deleteDirectoryRecursively(File path)
  7. deleteDirectoryRecursivly(String path)
  8. deleteDirectoryTree(String directoryPath)
  9. deleteDirRecursive(String dirPath)