I am trying to write a batch script to detect a USB drive and, if it is plugged in, for example copy c:\test\big.txt to the USB drive, and looping to detect another flash drive.
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.
Getting USB History With Single Powershell Command To do this, open powershell and type "Get-ItemProperty -Path HKLM:SYSTEMCurrentControlSetEnumUSBSTOR** | Select FriendlyName." Then press enter, and you will get the history of all USB devices that have been used on your computer.
@echo off
for %%d in (D: E: F: G: H: I: etc...) do (
if exist %%d\nul (
echo USB at drive %%d connected
)
)
EDIT: Below is the right way to do that:
@echo off
for /F "tokens=1*" %%a in ('fsutil fsinfo drives') do (
for %%c in (%%b) do (
for /F "tokens=3" %%d in ('fsutil fsinfo drivetype %%c') do (
if %%d equ Removable (
echo Drive %%c is Removable (USB^)
)
)
)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With