/**
* Get rid of ALL files and subdirectories in given directory, and all
* subdirs under it. The directory and subdirectories themselves are not deleted.
*
* @param pDir
* would normally be an existing directory.
* @param pRecursive
* true if want subdirs deleted as well
*/
public static void deleteDirContents ( File pDir, boolean pRecursive )
{
if ( pDir == null )
{
err.println( " no such directory" );
return;
}
if ( pRecursive )
{
String[] allDirs = pDir.list();
if ( allDirs != null )
{
for ( String subDir : allDirs )
{
deleteDirContents( new File( pDir, subDir ), true );
}
}
}
String[] allFilesAndDirsInThisDir = pDir.list();
if ( allFilesAndDirsInThisDir != null )
{
for ( String fileToDelete : allFilesAndDirsInThisDir )
{
deleteFile( new File( pDir, fileToDelete ) );
}
}
}