Skip to content

Instantly share code, notes, and snippets.

@startergo
Last active January 30, 2026 20:22
Show Gist options
  • Select an option

  • Save startergo/b30e0b273a7ed52e1f437059642d1342 to your computer and use it in GitHub Desktop.

Select an option

Save startergo/b30e0b273a7ed52e1f437059642d1342 to your computer and use it in GitHub Desktop.
Robocopy Helper

Robocopy File Transfer Helper

A user-friendly batch script that simplifies robocopy operations with an interactive interface, advanced exclusion options, and robust error handling.

Features

🚀 Core Functionality

  • Interactive setup - Step-by-step prompts for source and destination
  • Smart destination naming - Automatically creates properly named destination folders
  • Edit options - Modify source, destination, or exclusions at any step
  • Input validation - Checks paths and provides helpful error messages

📁 Advanced Exclusions

  • Folder exclusions - Exclude entire directories from copying
  • File pattern exclusions - Skip specific file types (*.tmp, *.log, etc.)
  • Preset exclusions - Common temp files and cache folders
  • Custom exclusions - Comma-separated list with proper space handling
  • Test mode - Preview what would be copied without actually copying

🔧 Network Reliability

  • Multi-threaded copying - 8 simultaneous threads for faster transfers
  • Restartable mode - Resume interrupted transfers automatically
  • Automatic retry logic - 3 retries with 30-second delays
  • Network optimization - Designed for reliable network file transfers

📊 Progress & Logging

  • Real-time progress - Shows transfer status with ETA
  • Timestamped logs - Detailed operation logs with completion status
  • Background transfers - Run transfers in background with progress monitoring
  • Interactive pause/resume - Stop and restart transfers as needed

Quick Start

  1. Download robocopy_helper.bat to your computer
  2. Double-click to run the script
  3. Follow the prompts:
    • Enter source folder path
    • Enter destination base path
    • Choose exclusion options
    • Confirm and start transfer

Usage Guide

Basic Copy Operation

Source: G:\Projects\MyProject
Destination: C:\Backup
Result: C:\Backup\MyProject\

Custom Exclusions

Exclude folders:

Tools,Photos,Cache,OLD Files

Exclude file types:

*.tmp,*.log,*.bak,thumbs.db

Transfer Options

  1. Start transfer now - Interactive foreground transfer
  2. Background transfer - Run in separate window with control menu
  3. Test mode - Preview without copying
  4. Resume transfer - Continue interrupted operations

Robocopy Parameters Used

Parameter Description
/E Copy subdirectories including empty ones
/MT:8 Multi-threaded copying (8 threads)
/Z Restartable mode for network reliability
/R:3 Retry failed copies 3 times
/W:30 Wait 30 seconds between retries
/DCOPY:DAT Copy directory timestamps and attributes
/ETA Show estimated time remaining
/LOG Create detailed log files
/TEE Display output to console and log

File Naming & Organization

Destination Folders

  • Source: Project Name with Spaces
  • Destination: C:\Backup\Project Name with Spaces\
  • Special characters (# & etc.) are cleaned automatically

Log Files

  • Format: robocopy_log_YYYYMMDD_HHMMSS.txt
  • Example: robocopy_log_20251219_143052.txt
  • Location: Same directory as the batch script

Troubleshooting

Common Issues

"No files copied"

  • Check if all files are in excluded folders
  • Try Test Mode to see what would be copied
  • Verify source path accessibility

"Folders not created"

  • Check destination path permissions
  • Avoid special characters in paths
  • Ensure sufficient disk space

"Script crashes"

  • Avoid quotes in folder names when prompted
  • Use comma separation (not spaces) for exclusions
  • Check for very long path names

Debug Information

The script provides comprehensive debug output:

  • Source and destination path validation
  • Exclusion parameter verification
  • Full robocopy command display
  • Real-time operation status

Best Practices

Exclusions

  • Use exact folder names as they appear in source
  • For spaces in names: OLD Files not OLD_Files
  • Test first with Test Mode to verify exclusions work
  • Be specific - don't exclude too broadly

Network Transfers

  • Use reliable connections for large transfers
  • Enable background mode for very large operations
  • Monitor logs for any network-related issues
  • Resume if interrupted - robocopy handles partial transfers well

File Organization

  • Use descriptive destination paths: C:\Projects\ not C:\
  • Check available disk space before large transfers
  • Review logs after completion for any issues

Advanced Features

Pause/Resume Workflow

  1. Start transfer (foreground or background)
  2. Press Ctrl+C to pause/stop
  3. Run script again with same settings
  4. Robocopy automatically skips already copied files

Background Transfer Control

  • View progress without interrupting transfer
  • Stop transfer cleanly when needed
  • Monitor completion automatically
  • Continue other work while transfer runs

Log Analysis

  • Success codes: 0-1 (perfect)
  • Minor issues: 2-3 (mostly successful)
  • Warnings: 4-7 (some files failed)
  • Errors: 8+ (major problems)

System Requirements

  • Windows 10/11 (or Windows Server with robocopy)
  • Network access to source locations
  • Write permissions to destination folders
  • PowerShell (for some advanced features)

Support

For issues or questions:

  1. Check debug output for specific error messages
  2. Review log files for detailed operation information
  3. Try Test Mode to diagnose exclusion issues
  4. Verify paths and permissions before reporting problems

Note: This script preserves original file timestamps while creating new folder timestamps, making it easy to find recently copied folders while maintaining file history.

@echo off
setlocal enabledelayedexpansion
title Robocopy File Transfer Helper
echo ===============================================
echo ROBOCOPY FILE TRANSFER HELPER
echo ===============================================
echo.
:GET_SOURCE
echo Please enter the SOURCE folder path:
set /p SOURCE_FOLDER=
if "%SOURCE_FOLDER%"=="" goto GET_SOURCE
echo Source: %SOURCE_FOLDER%
echo.
echo Is this correct? (y/N/e to edit):
set /p SOURCE_OK=
if /i "%SOURCE_OK%"=="e" goto GET_SOURCE
if /i not "%SOURCE_OK%"=="y" goto GET_SOURCE
echo.
:GET_DESTINATION
echo Please enter the DESTINATION folder path:
echo NOTE: A folder named after your source will be created here.
echo Example: If you enter C:\Backup, it will create C:\Backup\7865_GP_Palatka\
echo.
echo WARNING: Source folder contains special characters (# and &)
echo Recommended destination: C:\Projects or C:\Backup
set /p DEST_BASE=
if "%DEST_BASE%"=="" goto GET_DESTINATION
REM Extract the source folder name and clean it for destination
for %%i in ("%SOURCE_FOLDER%") do set SOURCE_NAME=%%~ni
REM Replace problematic characters with underscores
set SOURCE_NAME=%SOURCE_NAME:#=_%
set SOURCE_NAME=%SOURCE_NAME:&=and%
set SOURCE_NAME=%SOURCE_NAME: GP = GP_%
set DEST_FOLDER=%DEST_BASE%\%SOURCE_NAME%
echo Destination will be: %DEST_FOLDER%
echo.
echo Is this correct? (y/N/e to edit/b to go back to source):
set /p DEST_OK=
if /i "%DEST_OK%"=="e" goto GET_DESTINATION
if /i "%DEST_OK%"=="b" goto GET_SOURCE
if /i not "%DEST_OK%"=="y" goto GET_DESTINATION
echo.
:EXCLUSIONS
echo.
echo === EXCLUSIONS (Optional) ===
echo.
echo 1. Skip exclusions - copy everything
echo 2. Exclude common temp files (*.tmp, *.log, *.bak)
echo 3. Custom exclusions
echo 4. TEST MODE: List what would be copied (no actual copying)
echo 5. Go back to edit destination
echo 6. Go back to edit source
echo.
set /p EXCL_CHOICE="Choose option (1-6): "
if "%EXCL_CHOICE%"=="1" goto CONFIRM
if "%EXCL_CHOICE%"=="2" goto PRESET_EXCLUSIONS
if "%EXCL_CHOICE%"=="3" goto CUSTOM_EXCLUSIONS
if "%EXCL_CHOICE%"=="4" goto TEST_MODE
if "%EXCL_CHOICE%"=="5" goto GET_DESTINATION
if "%EXCL_CHOICE%"=="6" goto GET_SOURCE
goto EXCLUSIONS
:TEST_MODE
set "EXCL_PARAMS="
set "TEST_MODE=YES"
echo TEST MODE: Will show what would be copied without actually copying
goto CONFIRM
:PRESET_EXCLUSIONS
set EXCL_PARAMS=/XF *.tmp *.log *.bak thumbs.db desktop.ini
echo Will exclude: *.tmp *.log *.bak thumbs.db desktop.ini
goto CONFIRM
:CUSTOM_EXCLUSIONS
echo Enter folders to exclude (separate with commas):
echo IMPORTANT: Use exact folder names as they appear in the source
echo From your screenshot, the exact names are:
echo IWS_Install_sp4 (with underscore)
echo OLD Files (with space, not underscore)
echo.
echo So enter: IWS_Install_sp4,OLD Files
set /p EXCL_DIRS=
echo Enter files to exclude (separate with commas):
echo Example: *.tmp,*.log,*.bak
set /p EXCL_FILES=
set EXCL_PARAMS=
if not "%EXCL_DIRS%"=="" (
echo Will exclude folders: %EXCL_DIRS%
echo.
echo DEBUG: Building exclusion parameters...
REM Replace commas with a unique delimiter first
set "TEMP_DIRS=!EXCL_DIRS:,=|!"
REM Now process each folder name (preserving spaces)
set "EXCL_PARAMS="
for %%f in ("!TEMP_DIRS:|=" "!") do (
set "FOLDER_NAME=%%~f"
REM Add quotes around folder names that contain spaces
echo !FOLDER_NAME! | find " " >nul
if !errorlevel! equ 0 (
set "EXCL_PARAMS=!EXCL_PARAMS! /XD "!FOLDER_NAME!""
) else (
set "EXCL_PARAMS=!EXCL_PARAMS! /XD !FOLDER_NAME!"
)
)
echo DEBUG: Exclusion parameters: !EXCL_PARAMS!
echo.
)
if not "%EXCL_FILES%"=="" (
echo Will exclude files: %EXCL_FILES%
set "TEMP_FILES=!EXCL_FILES:,=|!"
for %%f in ("!TEMP_FILES:|=" "!") do (
set "FILE_NAME=%%~f"
set "EXCL_PARAMS=!EXCL_PARAMS! /XF !FILE_NAME!"
)
)
goto CONFIRM
:CONFIRM
echo.
echo ===============================================
echo CONFIRMATION
echo ===============================================
echo.
echo Ready to copy from:
echo %SOURCE_FOLDER%
echo To:
echo %DEST_FOLDER%
if defined EXCL_PARAMS echo Exclusions: !EXCL_PARAMS!
echo.
echo Robocopy options being used:
echo /E - Copy subdirectories including empty ones
echo /MT:8 - Multi-threaded copying (8 threads)
echo /Z - Restartable mode for network reliability
echo /R:3 - Retry 3 times on failed copies
echo /W:30 - Wait 30 seconds between retries
echo /DCOPY:DAT - Copy directory timestamps and attributes
echo /ETA - Show estimated time remaining
echo /LOG - Create detailed log file
echo.
echo PAUSE/RESUME: You can pause with Ctrl+C and resume by running this script again
echo with the same settings. Robocopy will skip already copied files.
echo.
echo Options:
echo 1. Proceed with copy
echo 2. Edit source folder
echo 3. Edit destination folder
echo 4. Edit exclusions
echo 5. Cancel
echo.
set /p CONFIRM_CHOICE="Choose option (1-5): "
if "%CONFIRM_CHOICE%"=="1" goto EXECUTE
if "%CONFIRM_CHOICE%"=="2" goto GET_SOURCE
if "%CONFIRM_CHOICE%"=="3" goto GET_DESTINATION
if "%CONFIRM_CHOICE%"=="4" goto EXCLUSIONS
if "%CONFIRM_CHOICE%"=="5" goto END
goto CONFIRM
:EXECUTE
echo.
echo ===============================================
echo STARTING ROBOCOPY OPERATION
echo ===============================================
echo.
REM Create log file with timestamp
set LOG_FILE=robocopy_log_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%time:~0,2%%time:~3,2%%time:~6,2%.txt
set LOG_FILE=%LOG_FILE: =0%
echo Log file: %LOG_FILE%
echo.
echo TRANSFER CONTROL:
echo - Press Ctrl+C to pause/stop the transfer
echo - To resume: Run this script again with same settings
echo - Robocopy will automatically skip already copied files
echo.
:TRANSFER_MENU
echo ===============================================
echo TRANSFER OPTIONS
echo ===============================================
echo.
echo 1. Start transfer now
echo 2. Start transfer in background (allows other operations)
echo 3. View current progress (if running in background)
echo 4. Cancel and return to main menu
echo.
set /p TRANSFER_CHOICE="Choose option (1-4): "
if "%TRANSFER_CHOICE%"=="1" goto START_TRANSFER
if "%TRANSFER_CHOICE%"=="2" goto START_BACKGROUND_TRANSFER
if "%TRANSFER_CHOICE%"=="3" goto VIEW_PROGRESS
if "%TRANSFER_CHOICE%"=="4" goto CONFIRM
goto TRANSFER_MENU
:START_TRANSFER
echo.
echo Starting transfer...
echo Press Ctrl+C at any time to stop. You can resume later with same settings.
echo.
echo DEBUG: Full robocopy command that will be executed:
echo robocopy "%SOURCE_FOLDER%" "%DEST_FOLDER%" /E /MT:8 /Z /R:3 /W:30 /DCOPY:DAT !EXCL_PARAMS! /LOG:%LOG_FILE% /TEE /ETA
echo.
echo DEBUG: Checking source and destination paths...
echo Source folder: "%SOURCE_FOLDER%"
echo Destination folder: "%DEST_FOLDER%"
echo Source exists:
if exist "%SOURCE_FOLDER%" (echo YES) else (echo NO - This might be the problem!)
echo Destination parent exists:
if exist "%DEST_FOLDER%\.." (echo YES) else (echo NO - Cannot create destination!)
echo.
echo DEBUG: Testing destination folder creation...
echo Creating destination folder if it doesn't exist...
if not exist "%DEST_FOLDER%" (
mkdir "%DEST_FOLDER%" 2>nul
if exist "%DEST_FOLDER%" (
echo SUCCESS: Destination folder created
) else (
echo ERROR: Could not create destination folder - check path and permissions
)
) else (
echo Destination folder already exists
)
echo.
echo Press any key to continue or Ctrl+C to cancel...
pause >nul
echo.
if "%TEST_MODE%"=="YES" (
echo RUNNING IN TEST MODE - NO FILES WILL BE COPIED
echo This will show what would be copied:
robocopy "%SOURCE_FOLDER%" "%DEST_FOLDER%" /E /L !EXCL_PARAMS!
) else (
echo RUNNING ACTUAL COPY OPERATION
robocopy "%SOURCE_FOLDER%" "%DEST_FOLDER%" /E /MT:8 /Z /R:3 /W:30 /DCOPY:DAT !EXCL_PARAMS! /LOG:%LOG_FILE% /TEE /ETA
)
set COPY_RESULT=%ERRORLEVEL%
goto TRANSFER_COMPLETE
:START_BACKGROUND_TRANSFER
echo.
echo Starting transfer in background...
echo You'll be returned to a menu where you can check progress or perform other operations.
echo.
REM Start robocopy in background and save PID
start "Robocopy Transfer" /MIN robocopy "%SOURCE_FOLDER%" "%DEST_FOLDER%" /E /MT:8 /Z /R:3 /W:30 /DCOPY:DAT %EXCL_PARAMS% /LOG:%LOG_FILE% /ETA
echo Transfer started in background window.
echo.
goto BACKGROUND_MENU
:BACKGROUND_MENU
echo ===============================================
echo BACKGROUND TRANSFER CONTROL
echo ===============================================
echo.
echo 1. View transfer progress
echo 2. Stop background transfer
echo 3. Wait for transfer to complete
echo 4. Return to main menu (transfer continues)
echo.
set /p BG_CHOICE="Choose option (1-4): "
if "%BG_CHOICE%"=="1" goto VIEW_PROGRESS
if "%BG_CHOICE%"=="2" goto STOP_TRANSFER
if "%BG_CHOICE%"=="3" goto WAIT_FOR_COMPLETE
if "%BG_CHOICE%"=="4" goto POST_OPERATION
goto BACKGROUND_MENU
:VIEW_PROGRESS
echo.
echo Current transfer progress (from log file):
echo ===============================================
if exist "%LOG_FILE%" (
echo Last 10 lines of transfer log:
powershell "Get-Content '%LOG_FILE%' -Tail 10"
) else (
echo Log file not yet created or transfer not started.
)
echo ===============================================
echo.
pause
goto BACKGROUND_MENU
:STOP_TRANSFER
echo.
echo Stopping background transfer...
taskkill /FI "WINDOWTITLE eq Robocopy Transfer*" /F >nul 2>&1
echo Transfer stopped. You can resume later using the same settings.
echo.
pause
goto POST_OPERATION
:WAIT_FOR_COMPLETE
echo.
echo Waiting for background transfer to complete...
echo Press Ctrl+C to return to menu (transfer will continue in background)
echo.
:WAIT_LOOP
timeout /t 5 >nul
tasklist /FI "WINDOWTITLE eq Robocopy Transfer*" 2>nul | find /i "cmd.exe" >nul
if errorlevel 1 (
echo.
echo Background transfer completed!
set COPY_RESULT=1
goto TRANSFER_COMPLETE
) else (
echo Transfer still running...
goto WAIT_LOOP
)
:TRANSFER_COMPLETE
echo.
echo ===============================================
echo OPERATION COMPLETED
echo ===============================================
echo.
if %COPY_RESULT% LEQ 1 (
echo SUCCESS: Files copied successfully!
) else if %COPY_RESULT% LEQ 3 (
echo COMPLETED: Some files copied with minor issues.
echo Check the log file for details.
) else if %COPY_RESULT% LEQ 7 (
echo WARNING: Copy completed but some files failed.
echo Check the log file for details.
) else (
echo ERROR: Copy operation failed!
echo Check the log file for details.
)
echo.
echo Copy completed!
echo.
echo Log file saved as: %LOG_FILE%
echo You can review the complete operation details in this log file.
echo.
:POST_OPERATION
echo What would you like to do next?
echo 1. Run another copy operation
echo 2. Resume/Continue this same operation (in case of interruption)
echo 3. View operation summary from log file
echo 4. Exit
echo.
set /p NEXT_ACTION="Choose option (1-4): "
if "%NEXT_ACTION%"=="1" goto GET_SOURCE
if "%NEXT_ACTION%"=="2" goto EXECUTE
if "%NEXT_ACTION%"=="3" goto VIEW_LOG
if "%NEXT_ACTION%"=="4" goto END
goto POST_OPERATION
:VIEW_LOG
echo.
echo Opening log file...
if exist "%LOG_FILE%" (
type "%LOG_FILE%" | more
) else (
echo Log file not found: %LOG_FILE%
)
echo.
goto POST_OPERATION
:END
echo.
echo Press any key to exit...
pause >nul
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment