• Based on this detailed specification: * draft the actual batch script and support files * produce the full folder‑aware mirroring logic * add color-coded output and countdown timers

  • Here's a draft of a batch script for Rclone Portable based on your detailed specifications. This script includes folder-aware mirroring logic, color-coded output, and countdown timers.

    Batch Script - rclone_mirror.bat

    @echo off
    SETLOCAL ENABLEDELAYEDEXPANSION
    
    :: Set paths and configurations
    SET "RCLONE_PATH=Programs\Rclone\rclone.exe"
    SET "CONFIG_PATH=Documents\Settings\rclone.conf"
    SET "TEMP_PATH=Documents\Settings\temp"
    SET "LOG_PATH=Documents\Settings\mirroring_log.txt"
    SET "RETRY_LIMIT=5"
    SET "DRY_RUN=0"
    
    :: Color definitions
    FOR /F "tokens=2 delims=: " %%G IN ('REG QUERY "HKCU\Console" /v "ColorTable0"') DO (
        SET BLUE=%%G
    )
    SET GREEN=0A
    SET RED=0C
    
    :: Function: Color-coded echo
    :echoColor
        SET "color=$1"
        SHIFT
        CALL COLOR !color!
        echo %*
        CALL COLOR
        EXIT /B
    
    :: Function: Countdown timer
    :countdown
        SET /A countdown=%1
        :countdown_loop
        IF !countdown! LEQ 0 (
            EXIT /B
        )
        CALL :echoColor 0A %countdown% seconds remaining...
        TIMEOUT /T 1 >nul
        SET /A countdown-=1
        GOTO countdown_loop
    
    :: Function: Check if drives are mounted
    :check_drives
        SET "mounted=0"
        FOR /D %%D IN (E:\ F:\) DO (
            IF EXIST "%%D\" SET "mounted=1" 
        )
        IF !mounted! EQU 0 (
            CALL :echoColor 0C USB Drives are not detected. Exiting...
            EXIT /B
        )
        CALL :echoColor 0A USB Drives detected.
        EXIT /B
    
    :: Function: Log messages
    :logMessage
        ECHO [%DATE% %TIME%] %1 >> "%LOG_PATH%"
        EXIT /B
    
    :: Function: Main mirroring operation
    :mirror
        CALL :check_drives
        CALL :logMessage "Starting mirroring operation..."
    
        REM Set options for Rclone
        SET "OPTIONS=--exclude=*.log --exclude=*.tmp --exclude=system_files --dry-run"
        
        IF %DRY_RUN% EQU 1 (
            SET "OPTIONS=!OPTIONS! --dry-run"
            CALL :logMessage "Dry run executed."
        )
    
        REM Perform the mirroring operation
        CALL "%RCLONE_PATH%" sync "source_path" "remote:path" !OPTIONS!
    
        :: Check the exit code and handle errors
        IF ERRORLEVEL 1 (
            CALL :echoColor 0C "Error during mirroring. Retrying..."
            SET /A retries=0
            :retry_loop
            SET /A retries+=1
            
            IF !retries! LEQ %RETRY_LIMIT% (
                CALL "%RCLONE_PATH%" sync "source_path" "remote:path" !OPTIONS!
                IF ERRORLEVEL 1 (
                    CALL :echoColor 0C "Retry %retries% failed. Exiting after %RETRY_LIMIT% retries."
                    EXIT /B
                ) ELSE (
                    CALL :echoColor 0A "Mirroring completed successfully on retry %retries%."
                    CALL :logMessage "Successful mirroring after %retries% retry."
                    EXIT /B
                )
                GOTO retry_loop
            )
        ) ELSE (
            CALL :echoColor 0A "Mirroring completed successfully."
            CALL :logMessage "Mirroring completed without errors."
        )
    
        EXIT /B
    
    :: Main menu for user interaction
    :menu
        CLS
        CALL :echoColor 0A "Rclone Portable - Main Menu"
        CALL :echoColor 0E "1: Check and Clear Temp Folder"
        CALL :echoColor 0E "2: Mirror"
        CALL :echoColor 0E "Q: Quit"
        
        SET /P option=Choose an option: 
        IF "%option%"=="2" CALL :mirror
        IF "%option%"=="1" (
            CALL :echoColor 0A "Clearing temp folder..."
            DEL /Q "%TEMP_PATH%\*"
            CALL :logMessage "Temp folder cleared."
        )
        IF /I "%option%"=="Q" EXIT /B
    
        GOTO menu
    
    :: Initial function calls
    CALL :menu
    
    ENDLOCAL
    

    Supporting Functions

    You can create additional supporting scripts if needed. For example, you could include a log_viewer.bat for viewing log files or a settings_manager.bat to manage settings.

    Directory Structure

    Ensure you have the following folder structure on your USB drive for the script to work effectively:

    USB Drive Root
    │
    ├── Programs
    │   ├── Rclone
    │       └── rclone.exe
    │
    ├── Documents
    │   ├── Settings
    │       ├── rclone.conf
    │       ├── mirroring_log.txt
    │       └── temp (directory for temporary files)
    

    Notes

    • The script checks if designated USB drives are mounted.
    • When mirroring, it supports exclusion of certain file types.
    • There is a retry mechanism for handling errors.
    • The output is color-coded for easier reading.

    Ensure you tailor the paths and configurations according to your specific environment. This setup provides a solid basis for the batch file script you requested.

      RELATED QUESTIONS