public static void moveDirectoryToDirectory(File src, File destDir, boolean createDestDir) {
   try {
     FileUtils.moveDirectoryToDirectory(src, destDir, createDestDir);
   } catch (IOException e) {
     throw new UncheckedIOException(e);
   }
 }
  @Override
  public FileSystemEntryDTO moveDirectory(String fullPath, String newParent, String newName)
      throws FileErrorException {
    File basePath = new File(path);

    File directory = new File(basePath, fullPath);
    ensureLocalRoot(basePath, directory);

    ensureLocalRoot(basePath, directory);

    File baseDir = new File(basePath, newParent);

    ensureLocalRoot(basePath, baseDir);

    File newDir = new File(baseDir, newParent);

    try {
      FileUtils.moveDirectoryToDirectory(directory, newDir, true);

      FileSystemEntryDTO dto = new FileSystemEntryDTO();

      dto.setFile(false);
      String absolutePath = newDir.getAbsolutePath();
      String tmpPath = absolutePath.substring(path.length(), absolutePath.length());
      dto.setFullPath(tmpPath);
      dto.setName(directory.getName());
      return dto;

    } catch (IOException e) {
      logger.log(Level.SEVERE, "can not move directory", e);
      throw new FileErrorException(FileError.INVALID_STATE_ERR);
    }
  }
  @RequestMapping("move")
  public String move(
      @RequestParam(value = "descPath") String descPath,
      @RequestParam(value = "paths") String[] paths,
      @RequestParam(value = "conflict") String conflict,
      RedirectAttributes redirectAttributes)
      throws IOException {

    String rootPath = sc.getRealPath(ROOT_DIR);
    descPath = URLDecoder.decode(descPath, Constants.ENCODING);

    for (int i = 0, l = paths.length; i < l; i++) {
      String path = paths[i];
      path = URLDecoder.decode(path, Constants.ENCODING);
      paths[i] = (rootPath + File.separator + path).replace("\\", "/");
    }

    try {
      File descPathFile = new File(rootPath + File.separator + descPath);
      for (String path : paths) {
        File sourceFile = new File(path);
        File descFile = new File(descPathFile, sourceFile.getName());
        if (descFile.exists() && "ignore".equals(conflict)) {
          continue;
        }

        FileUtils.deleteQuietly(descFile);

        if (sourceFile.isDirectory()) {
          FileUtils.moveDirectoryToDirectory(sourceFile, descPathFile, true);
        } else {
          FileUtils.moveFileToDirectory(sourceFile, descPathFile, true);
        }
      }
      redirectAttributes.addFlashAttribute(Constants.MESSAGE, "移动成功!");
    } catch (Exception e) {
      redirectAttributes.addFlashAttribute(Constants.ERROR, e.getMessage());
    }

    redirectAttributes.addAttribute("path", URLEncoder.encode(descPath, Constants.ENCODING));
    return redirectToUrl(viewName("list"));
  }
  /*
   * Move files from current location into new one
   */
  protected void upgradeV49() {

    String location = prefs.getString(PrefsActivity.PREF_STORAGE_LOCATION, "");
    if (!location.equals("")) {
      return;
    }

    String source =
        Environment.getExternalStorageDirectory()
            + File.separator
            + Storage.APP_ROOT_DIR_NAME
            + File.separator;

    File[] dirs = ContextCompat.getExternalFilesDirs(ctx, null);
    if (dirs.length > 0) {

      String destination = dirs[dirs.length - 1].getAbsolutePath();
      File downloadSource = new File(source + Storage.APP_DOWNLOAD_DIR_NAME);
      File mediaSource = new File(source + Storage.APP_MEDIA_DIR_NAME);
      File courseSource = new File(source + Storage.APP_COURSES_DIR_NAME);

      publishProgress(this.ctx.getString(R.string.upgradev49_1, ""));
      try {
        org.apache.commons.io.FileUtils.forceDelete(
            new File(destination + File.separator + Storage.APP_DOWNLOAD_DIR_NAME));
      } catch (IOException e) {
        // TODO Auto-generated catch block
        Log.d(
            TAG,
            "failed to delete: " + destination + File.separator + Storage.APP_DOWNLOAD_DIR_NAME);
        e.printStackTrace();
      }

      try {
        org.apache.commons.io.FileUtils.forceDelete(
            new File(destination + File.separator + Storage.APP_MEDIA_DIR_NAME));
      } catch (IOException e) {
        // TODO Auto-generated catch block
        Log.d(
            TAG, "failed to delete: " + destination + File.separator + Storage.APP_MEDIA_DIR_NAME);
        e.printStackTrace();
      }

      try {
        org.apache.commons.io.FileUtils.forceDelete(
            new File(destination + File.separator + Storage.APP_COURSES_DIR_NAME));
      } catch (IOException e) {
        // TODO Auto-generated catch block
        Log.d(
            TAG,
            "failed to delete: " + destination + File.separator + Storage.APP_COURSES_DIR_NAME);
        e.printStackTrace();
      }

      // now copy over
      try {

        org.apache.commons.io.FileUtils.moveDirectoryToDirectory(
            downloadSource, new File(destination), true);
        Log.d(TAG, "completed");
      } catch (IOException e) {
        // TODO Auto-generated catch block
        Log.d(TAG, "failed");
        e.printStackTrace();
      }

      try {
        org.apache.commons.io.FileUtils.moveDirectoryToDirectory(
            mediaSource, new File(destination), true);
        Log.d(TAG, "completed");
      } catch (IOException e) {
        // TODO Auto-generated catch block
        Log.d(TAG, "failed");
        e.printStackTrace();
      }

      try {
        org.apache.commons.io.FileUtils.moveDirectoryToDirectory(
            courseSource, new File(destination), true);
        Log.d(TAG, "completed");

      } catch (IOException e) {
        // TODO Auto-generated catch block
        Log.d(TAG, "failed");
        e.printStackTrace();
      }

      Editor editor = prefs.edit();
      editor.putString(PrefsActivity.PREF_STORAGE_LOCATION, destination);
      editor.apply();

      // delete original dir
      try {
        org.apache.commons.io.FileUtils.forceDelete(new File(source));
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Log.d(TAG, "failed to delete original file");
      }
    }
  }
 public static void moveDirectory(File src, File destDir, boolean createDestDir)
     throws IOException {
   FileUtils.moveDirectoryToDirectory(src, destDir, createDestDir);
 }