code: private void removeFolder(File dir) throws IOException 
     {
        if (PrivilegedFileHelper.isDirectory(dir))
        {  
           for (File subFile : PrivilegedFileHelper.listFiles(dir))
           {
              removeFolder(subFile);
           }
           
           if (!PrivilegedFileHelper.delete(dir))
           {
              throw new IOException("Index folder was not deleted : " + PrivilegedFileHelper.getCanonicalPath(dir));
           }
        }
        else
        {
           if (!PrivilegedFileHelper.delete(dir))
           {
              throw new IOException("Index file was not deleted : " + PrivilegedFileHelper.getCanonicalPath(dir));
           }
        }
     }
docs: Remove folder