Recursively Delete Directory
11
mattrmiller
Recursively delete a directory, emptying all contents.
// Delete directory
public static boolean deleteDir(String strFile)
{
// Declare variables variables
File fDir = new File(strFile);
String[] strChildren = null;
boolean bRet = false;
// Validate directory
if (fDir.isDirectory())
{
// -- Get children
strChildren = fDir.list();
// -- Go through each
for (int i = 0; i < strChildren.length; i++)
{
bRet = deleteDir(new File(fDir, strChildren[i]).getAbsolutePath());
if (!bRet)
{
return false;
}
}
}
// The directory is now empty so delete it
return fDir.delete();
}
Comments
Sat. Oct. 28th, 2006 2:05 PM
SCoon
SCoon





