Android File Delete deleteFolder(File targetFolder)

Here you can find the source of deleteFolder(File targetFolder)

Description

delete Folder

Declaration

public static boolean deleteFolder(File targetFolder) 

Method Source Code

//package com.java2s;

import java.io.File;

public class Main {
    public static boolean deleteFolder(File targetFolder) {
        try {//from w w w.j  a va  2 s .  co m
            File[] childFile = targetFolder.listFiles();

            if (childFile == null) {
                return !targetFolder.exists();
            }

            int size = childFile.length;

            if (size > 0) {
                for (int i = 0; i < size; i++) {
                    if (childFile[i].isFile()) {
                        childFile[i].delete();
                    } else {
                        deleteFolder(childFile[i]);
                    }
                }
            }

            targetFolder.delete();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return !targetFolder.exists();
    }
}

Related

  1. deleteFile(String strSrc)
  2. deleteFileOnly(String path)
  3. deleteFiles(File file)
  4. deleteFiles(File file, String regex)
  5. deleteFilesRecursive(File src)
  6. deleteFolders(File dir)
  7. deleteIfExists(File file)
  8. deleteOldFile(String strPath, String strWildcard, int iOffset)
  9. deleteRecursively(File dir)