Exemplo n.º 1
0
  /** Recursive function for deleteAll */
  private boolean deleteDirectoryContent(LocalFile directory) {

    boolean result = true;
    if (directory.exists()) {
      if (directory.isDirectory()) {
        LocalFile[] list = directory.listFiles();
        if (list.length > 0) {
          for (LocalFile element : list) {
            result = result && deleteDirectoryContent(element);
            if (element.exists()) {
              result = result && removeFile(element);
            }
          }
        } else {
          // The directory is empty and it is deleted by the if in the
          // for loop above
        }
      } else {
        result = removeFile(directory);
      }
    }
    return result;
  }
Exemplo n.º 2
0
  private boolean removeFile(LocalFile file) {

    boolean result = false;
    LocalFile[] list;
    if (file.exists()) {
      if (file.isDirectory()) {
        list = file.listFiles();
        if (list.length > 0) {
          result = false;

          log.info("{} : Unable to delete non-empty directory {}", SRM_COMMAND, file);

        } else {
          result = file.delete();
        }
      } else {
        result = file.delete();
      }
    } else {
      result = false;
      log.debug("{}: file {} does not exist", SRM_COMMAND, file);
    }
    return result;
  }