Here you can find the source of deleteNonEmptyDirectory(String dirPath)
Parameter | Description |
---|---|
dirPath | a parameter |
public static boolean deleteNonEmptyDirectory(String dirPath)
//package com.java2s; import java.io.File; public class Main { /**/*ww w . ja v a2 s.c om*/ * Deletes a non-empty directory, defined by dirPath from the file system. * Returns true, if directory and all the files, contained in it, have been * deleted. * * @param dirPath * @return */ public static boolean deleteNonEmptyDirectory(String dirPath) { File dir = new File(dirPath); if (dir.exists() && dir.isDirectory()) { File[] files = dir.listFiles(); for (int i = 0; i < files.length; i++) { File file = files[i]; boolean fileDeleted = file.delete(); if (!fileDeleted) return false; } return dir.delete(); } else return false; } }