code: private void deleteIfEmpty(File dir) {
          String[] r = dir.list();
          if(r==null)     return; // can happen in a rare occasion
          if(r.length==0)
              dir.delete();
      }
docs: Deletes a directory if it's empty.