By Ivy / Last update April 8, 2022

Content of this article:

How to automatically copy files when USB drive connected to your PC?

“I am looking for a solution for copying all the files from a specific directory on the hard drive, to a specific directory on a USB memory device, once this device is connected.”

Do you have similar problem? How to automatically copy files when USB drive connected? If so, keep reading below to learn the detailed steps. In the following, you will learn 2 useful methods, including backing up files with a professional backup software,  copying files with autorun.inf and.bat file. 

Automatically Copy Files When USB Drive Connedted

Easy way: Automatically copy files from/to USB drive when connected

In this part, you will use "USB plug in" feature in AOMEI Backupper Professional to automatically backup flash drive when plugged in or automatically copy files to USB drive when it is connected to your PC. To make it, you need to create a schedule backup with USB plug in feature first.  Then, you just need to plug it into your computer and it will automatically backup files from/to USB drive.

Before start, you need to do some preparations.
1. Prepare a USB flash drive and connect it to your computer. 
2. Download AOMEI Backupper Professional, install and launch it.

Download Free Trial Win 11/10/8.1/8/7/XP
Secure Download

Then, learn how to automatically copy files to USB drive when connected. 

  1. Open AOMEI Backupper Professional, then click Backup and File Backup.

File Backup

  1. Click Add Folder or Add File to select whatever you want to backup and click OK.

Add File or Folder

  1. Click the drop-down menu and select the connected flash drive as the target drive.

Select Backup Destination

  1. (Required) Click Schedule at the bottom and then select USB plug in feature.

Schedule Settings General

  1. Click Start Backup. After that, you need to check if it will automatically copy files when USB drive connected.

With the help of AOMEI Backupper Professional, it's easy to automatically copy files from/to USB drive when connected. But this version only support Windows 7/8/10/11. If you are a server user, you could consider using AOMEI Backupper Server(support server from 2003 to 20222). 

Besides, you can use AOMEI Backupper to create a bootable media. With this bootable media, you can even copy files without booting Windows. This useful tool can also help you start your computer successfully when you experience a system crash.

Complicated way: Automatically copy files when USB drive connected 

To automatically backup files with autorun.inf and .bat file, you need to create 5 files with Notepad, namely, AutoRun.inf, drive.ico, file.bat, launch.bat, invisible.vbs, and then run the backup task by clicking file.bat. Now, see the detailed steps below.

Autorun Batch File

  1. Create an autorun file for the flash drive. Copy and paste the following code to notepad and save as AutoRun.inf. The file type needs to be all file.
  • [autorun]
  • icon=drive.ico 
  • open=launch.bat
  • action=Click ok to Run game for Windows
  • shell\open\command=launch.bat

Notes:
▶ .ico refers to a png file. You have to find a png file and save it to the flash drive, then and name it as drive.ico.
▶ open is used to launch the batch file.
▶ action refers to open whatever you want.

  1. Copy and paste the following code and save as file.bat. You can replace “picture”,”Favorites”,”videos” with your own needs.
  • @echo off
  • :: variables
  • /min
  • SET odrive=%odrive:~0,2%
  • set backupcmd=xcopy /s /c /d /e /h /i /r /y
  • echo off
  • %backupcmd% "%USERPROFILE%\pictures" "%drive%\all\My pics"
  • %backupcmd% "%USERPROFILE%\Favorites" "%drive%\all\Favorites"
  • %backupcmd% "%USERPROFILE%\videos" "%drive%\all\vids"
  • @echo off
  • cls
  1. Create a VB Script file to batch file as invisible. Type the following syntax in the notepad and save as invisible.vbs.
  • CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
  1. Make a batch file to run vb script and file.bat. Type the following code in the notepad and save as launch.bat.
  • wscript.exe \invisible.vbs file.bat
  1. Create a folder in the root of flash drive and name it as all. Then, save all the files in the folder and make it hidden. After that, test if the batch file works for automatically copy files when USB drive connected.

Wrapping things up

Speaking of automatically copying files when USB drive connected, there are 2 useful ways for you. If you want an easy way, you could use "USB plug in" feature in AOMEI Backupper Professional. If you want to set a batch file, you could try the second yet complicated way. 

Except for copying files, AOMEI Backupper still offers multiple useful features, allowing you to automatic backup Windows 7 to network drive, sync folder to Google Drive, delete old backup, clone dual boot hard drive, etc.