code: public static void renameRecursively(FileSystem fileSystem, Path from, Path to) throws IOException {
  
      log.info(String.format("Recursively renaming %s in %s to %s.", from, fileSystem.getUri(), to));
  
      FileSystem throttledFS = getOptionallyThrottledFileSystem(fileSystem, 10000);
  
      ExecutorService executorService = ScalingThreadPoolExecutor.newScalingThreadPool(1, 100, 100,
          ExecutorsUtils.newThreadFactory(Optional.of(log), Optional.of("rename-thread-%d")));
      Queue<Future<?>> futures = Queues.newConcurrentLinkedQueue();
  
      try {
        if (!fileSystem.exists(from)) {
          throw new IOException("Trying to rename a path that does not exist! " + from);
        }
  
        futures.add(executorService
            .submit(new RenameRecursively(throttledFS, fileSystem.getFileStatus(from), to, executorService, futures)));
        int futuresUsed = 0;
        while (!futures.isEmpty()) {
          try {
            futures.poll().get();
            futuresUsed++;
          } catch (ExecutionException | InterruptedException ee) {
            throw new IOException(ee.getCause());
          }
        }
  
        log.info(String.format("Recursive renaming of %s to %s. (details: used %d futures)", from, to, futuresUsed));
  
      } finally {
        ExecutorsUtils.shutdownExecutorService(executorService, Optional.of(log), 1, TimeUnit.SECONDS);
      }
    }
docs: This method is an additive implementation of the {@link FileSystem#rename(Path, Path)} method. It moves all the
  files/directories under 'from' path to the 'to' path without overwriting existing directories in the 'to' path.
  
  <p>
  The rename operation happens at the first non-existent sub-directory. If a directory at destination path already
  exists, it recursively tries to move sub-directories. If all the sub-directories also exist at the destination,
  a file level move is done
  </p>
  
  @param fileSystem on which the data needs to be moved
  @param from path of the data to be moved
  @param to path of the data to be moved