Android File Delete deleteRecursively(File dir)

Here you can find the source of deleteRecursively(File dir)

Description

Deletes a file recursively.

License

Open Source License

Parameter

Parameter Description
dir a parameter

Declaration

public static boolean deleteRecursively(File dir) 

Method Source Code

//package com.java2s;
/**//from   w ww .j  a va 2  s.c  o  m
 * Aptana Studio
 * Copyright (c) 2005-2011 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the GNU Public License (GPL) v3 (with exceptions).
 * Please see the license.html included with this distribution for details.
 * Any modifications to this file must keep this entire header intact.
 */

import java.io.File;

public class Main {
    /**
     * Deletes a file recursively. If it's a directory we delete depth first, then delete the directory. The result is
     * true only if the directory and all it's children are deleted.
     * 
     * @param dir
     * @return
     */
    public static boolean deleteRecursively(File dir) {
        if (dir == null) {
            return false;
        }
        boolean result = true;
        if (dir.isDirectory()) {
            for (File child : dir.listFiles()) {
                result = result && deleteRecursively(child);
            }
        }
        return result && dir.delete();
    }
}

Related

  1. deleteFilesRecursive(File src)
  2. deleteFolder(File targetFolder)
  3. deleteFolders(File dir)
  4. deleteIfExists(File file)
  5. deleteOldFile(String strPath, String strWildcard, int iOffset)
  6. deleteRecursively(File f)
  7. deleteSubfiles(String publishTemppath)
  8. deleteTempDir(File dir)
  9. deleteTempFile(File tmpFile)