Пример #1
0
 /**
  * moves a folder from one location in a webdav server to another using the current domain
  *
  * @param src The path relative to the domain for the source folder
  * @param des The path relative to the domain for the destination folder
  * @param overwrite If there is an existing folder, it will be overwritten if this parameter is
  *     set to true
  * @return The complete path of the folder created or null if not created
  */
 public String moveFolder(String src, String des, boolean overwrite) {
   String result = null;
   try {
     if (_isLocal) {
       File tmpFile = new File(_rootFile.getCanonicalPath() + File.separatorChar + src);
       if (tmpFile.renameTo(new File(_rootFile.getCanonicalPath() + File.separatorChar + des))) {
         tmpFile = new File(_rootFile.getCanonicalPath() + File.separatorChar + des);
         result = tmpFile.getCanonicalPath();
       }
     } else {
       result = _remote.moveFolder(_domain, src, des, overwrite);
     }
   } catch (Exception ex) {
     ex.printStackTrace();
   }
   return result;
 }
Пример #2
0
  /**
   * rename an existing file using the current domain
   *
   * @param oldPath The current path relative to the domain for the file
   * @param newName The new name of the file
   * @return The complete path of the file or null if method failed
   */
  public String renameFolder(String oldPath, String newName) {
    String result = null;
    String newPath = null;
    int endPoint = oldPath.lastIndexOf(File.separatorChar);
    if (endPoint == oldPath.length() - 1)
      newPath =
          oldPath.substring(0, oldPath.lastIndexOf(File.separatorChar, endPoint - 1)) + newName;
    else if (endPoint == -1) newPath = newName;
    else newPath = oldPath.substring(0, endPoint + 1) + newName;

    try {
      if (_isLocal) result = moveFolder(_domain, oldPath, newPath, false);
      else result = _remote.moveFolder(_domain, oldPath, newPath, false);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return result;
  }