// sample recursive method that descends a directory tree

/**
 * 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;
      }

   // Empty child subdirs files before we get rid of
   // immediate files of this dir.
   if ( pRecursive )
      {
      String[] allDirs = pDir.list();
      if ( allDirs != null )
         {

         for ( String subDir : allDirs )
            {
            deleteDirContents( new File( pDir, subDir ), true );
            }
         }
      }
   // delete all files and subdirs in this dir
   String[] allFilesAndDirsInThisDir = pDir.list();
   if ( allFilesAndDirsInThisDir != null )
      {
      for ( String fileToDelete : allFilesAndDirsInThisDir )
         {
         deleteFile( new File( pDir, fileToDelete ) );
         }
      }
   } // end