Append suffix (#) to copied file if destination filename exist

What is the problem you are having with rclone?

With rclone is it possible so it appends a appropriate suffix (#) to the copied file if a file with the same name exist in the destination directory? Exactly how windows explorer handles the filenames, appending (0), (1), (2) etc. to the copied over file.

Currently using the --suffix but it seem to handle by instead renaming the destination file with the suffix instead of the copied file, and it also seem to overwrite the destination file if there already exist a same filename with the suffix too whereas I expect it to instead append a (1) suffix instead like how windows explorer does it.

The command you were trying to run (eg rclone copy /tmp remote:tmp)

rclone copy sourcedir destinationdir --create-empty-src-dirs --suffix "(0)"

Well ended up creating a python script to do this, not good as it passes on single files one at a time to rclone when doing the copyto but there you go.

import os
import subprocess
import datetime

def printRed(skk):
def printGreen(skk):
def printYellow(skk):
def printCyan(skk):

logPath = "C:/Users/"

while True:
    # Set move operation
    while True:
        print("1. Sync\n"
              "2. Copyto\n"
              "3. Move")
        move_operation = input("Enter the move operation (1, 2, or 3): ")
        if move_operation == "1":
            move_operation = "sync"
        elif move_operation == "2":
            move_operation = "copyto"
        elif move_operation == "3":
            move_operation = "move"
            printRed("Invalid input, try again")
    printCyan(f"Selected move operation: {move_operation}")

    while True:
        if move_operation == "copyto":
            checksum = None
        checksum = input("Enabled checksum checks? (Y/N): ")
        checksum = checksum.upper()
        if checksum == "Y":
            checksum = "--checksum"
            printCyan("Checksum checks enabled")
        elif checksum == "N":
            printCyan("Checksum checks disabled")
            checksum = None
            printRed("Invalid input, try again")

    while True:
        # Set source path
        while True:
            source_path = input("Enter the source directory path: ")
            source_path = source_path.replace('"',"")
            if os.path.isdir(source_path):
                printCyan(f"Selected source path: {source_path}")
                printRed("Directory path not found, try again")

        # Set destination path
        while True:
            destination_path = input("Enter the destination directory path: ")
            destination_path = destination_path.replace('"',"")
            if os.path.isdir(destination_path):
                printCyan(f"Selected destination path: {destination_path}")
                printRed("Directory path not found, try again")
        if source_path == destination_path:
            printRed(f"Source and destination path cannot be the same")
    input("Press any key to continue move operation")

    # Get the current date and time
    current_datetime =

    # Format the date as YYYY-MM-DD
    formatted_date = current_datetime.strftime('%Y-%m-%d')

    # Format the time as
    formatted_time = current_datetime.strftime('%H.%M.%S')

    if move_operation == "copyto":
        # Iterate over files in the source directory
        for root, subdirs, files in os.walk(source_path):
            for file in files:
                source_file = os.path.join(root, file)

                # Construct the destination file path
                relative_path = os.path.relpath(root, source_path)
                destination_file = os.path.join(destination_path, relative_path, file)

                # Check if the file already exists in the destination
                counter = 0
                base, ext = os.path.splitext(file)
                while os.path.exists(destination_file):
                    new_filename = f"{base} ({counter}){ext}"
                    destination_file = os.path.join(destination_path, relative_path, new_filename)
                    counter += 1
                cmd_args = ["rclone", move_operation, source_file, destination_file, "--metadata", "--progress", "--log-file=" + logPath + f"{move_operation} source to destination - Date=" + formatted_date + " & Time=" + formatted_time + ".log", "--log-level=INFO"]
        cmd_args = ["rclone", move_operation, source_path, destination_path, "--metadata", "--progress", "--check-first", "--create-empty-src-dirs", "--transfers=20", "--checkers=20", "--log-file=" + logPath + f"{move_operation} source to destination - Date=" + formatted_date + " & Time=" + formatted_time + ".log", "--log-level=INFO"]
        if checksum:

    current_datetime2 =
    timeTaken = current_datetime2 - current_datetime

    # Get the total seconds elapsed
    total_seconds = timeTaken.total_seconds()

    # Calculate hours, minutes, and seconds
    hours, remainder = divmod(total_seconds, 3600)
    minutes, seconds = divmod(remainder, 60)

    # Format as HH.MM.SS
    formatted_time = f"Total elapsed time: {int(hours):d}h {int(minutes):d}min {int(seconds):d}s"

nice script.

maybe, instead of for each file, use the rclone api

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.