Fast File Transfer In Windows

File Transfer Utility: A Robust Batch Script for Efficient File Operations

In today’s digital world, managing files efficiently is crucial, whether you’re a system administrator, developer, or just a power user. Manually copying or moving large folders can be tedious and error-prone. That’s where automation comes in!

In this blog post, I’ll introduce a File Transfer Utility—a Windows batch script that simplifies file copying and moving operations using Robocopy, a more powerful alternative to the traditional xcopy and move commands.


Why Use This Script?

  1. Faster & More Reliable Copying with Robocopy
    • Handles large files and directories better than xcopy.
    • Supports resume functionality in case of interruptions.
    • Provides detailed logging for troubleshooting.
  2. Simple & User-Friendly Interface
    • Menu-driven approach for easy selection (Copy, Move, or Exit).
    • Confirmation prompt to prevent accidental operations.
  3. Logging & Error Handling
    • Generates a transfer.log file for tracking operations.
    • Proper error detection for both copy and move operations.

The Script (Using Robocopy for Enhanced Performance)

batch

Copy

Download

@echo off
title File Transfer Utility - By Manish Acharya
color 0A

:MAIN
cls
echo **********************************************
echo      FILE TRANSFER UTILITY v1.0
echo      Developed by Manish Acharya
echo **********************************************
echo.
echo 1. Copy Files/Folders
echo 2. Move Files/Folders
echo 3. Exit
echo.
set /p choice="Enter your choice (1-3): "

if "%choice%"=="1" goto COPY
if "%choice%"=="2" goto MOVE
if "%choice%"=="3" exit
echo Invalid choice, please try again.
pause
goto MAIN

:COPY
set operation=copy
goto GETPATHS

:MOVE
set operation=move
goto GETPATHS

:GETPATHS
cls
echo **********************************************
echo      %operation% OPERATION
echo **********************************************
echo.
set /p source="Enter source path: "
set /p destination="Enter destination path: "

echo.
echo You are about to %operation% from:
echo %source%
echo to:
echo %destination%
echo.
set /p confirm="Confirm (Y/N): "

if /i "%confirm%" neq "Y" (
    echo Operation cancelled.
    pause
    goto MAIN
)

if "%operation%"=="copy" (
    echo Copying files with robocopy...
    robocopy "%source%" "%destination%" /E /ZB /R:3 /W:10 /V /TEE /LOG+:transfer.log
    if %errorlevel% LSS 8 (
        echo Operation completed successfully.
        echo Details logged in transfer.log
    ) else (
        echo Error occurred during operation.
        echo Check transfer.log for details
    )
) else (
    echo Moving files...
    move /Y "%source%" "%destination%"
    if errorlevel 1 (
        echo Error occurred during operation.
    ) else (
        echo Operation completed successfully.
    )
)
pause
goto MAIN

Key Features Explained

1. Robocopy for Superior File Copying

Robocopy (Robust File Copy) is a command-line tool built into Windows that outperforms xcopy in many ways:

  • /E – Copies all subdirectories, including empty ones.
  • /ZB – Uses restartable mode (helpful for network transfers).
  • /R:3 – Retries failed copies up to 3 times.
  • /W:10 – Waits 10 seconds between retries.
  • /V – Provides verbose logging.
  • /TEE – Displays output on screen and in log file.
  • /LOG+:transfer.log – Saves a detailed log for review.

2. Move Command for Simple Relocation

For moving files, the script uses the standard move command with /Y to suppress confirmation prompts.

3. Error Handling & Logging

  • Robocopy returns exit codes (0-7 = success, 8-16 = error).
  • The script checks errorlevel and informs the user if something went wrong.
  • All operations are logged in transfer.log for troubleshooting.

How to Use the Script?

  1. Save the Script
    • Open Notepad, paste the code, and save as FileTransferUtility.bat.
  2. Run as Administrator (Recommended)
    • Right-click the file and select “Run as Administrator” to avoid permission issues.
  3. Follow the Menu Prompts
    • Choose 1 (Copy) or 2 (Move).
    • Enter source and destination paths.
    • Confirm with Y to proceed.
  4. Check the Logs
    • If any errors occur, review transfer.log for details.

Conclusion

This File Transfer Utility is a simple yet powerful tool for automating file operations. By leveraging Robocopy, it ensures faster, more reliable copying with detailed logging—making it ideal for backups, data migrations, or general file management.

Give it a try and let me know your thoughts in the comments!

🔹 Download the script: [GitHub Gist Link] (optional: upload to GitHub and link)
🔹 Need enhancements? Feel free to modify it for your needs!

Happy scripting! 🚀

— Manish Acharya


Posted

in

by

Tags: