Here you can find the source of deleteSubdirs(String directory)
Parameter | Description |
---|---|
directory | the directory where to delete the subdirectories from |
public static void deleteSubdirs(String directory)
//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(); } } } }