Android Directory Delete deleteSubdirs(String directory)

Here you can find the source of deleteSubdirs(String directory)

Description

Deletes all subdirectories of the given directory.

Parameter

Parameter Description
directory the directory where to delete the subdirectories from

Declaration

public static void deleteSubdirs(String directory) 

Method Source Code

//package com.java2s;

import java.io.File;

public class Main {
    /**//from  ww w .  j a  v a 2s  . co m
     * Deletes all subdirectories of the given directory.
     * @param directory the directory where to delete the subdirectories from
     */
    public static void deleteSubdirs(String directory) {
        File parentDir = new File(directory);
        String[] list = parentDir.list();
        File subDir;

        if (list.length == 0) {
            return;
        }

        for (int i = 0; i < list.length; i++) {
            subDir = new File(directory, list[i]);
            if (subDir.isDirectory()) {
                String[] fileList = subDir.list();
                if (fileList.length > 0) {
                    for (int j = 0; j < fileList.length; j++) {
                        File file = new File(subDir.getAbsoluteFile(),
                                fileList[j]);
                        file.delete();
                    }
                }
                subDir.delete();
            }
        }
    }
}

Related

  1. deleteDirectory(String path)
  2. deleteDirectory(final File directory)
  3. deleteFiles(String directory)
  4. deleteFiles(String directory, String dontDelete)
  5. deleteFiles(String directory, String[] dontDelete)
  6. removerDiretorio(File dir)
  7. deleteDirectory(File path)
  8. deleteDir(File dir)
  9. deleteDir(File f)