:: By LJ_SunTB【Baidu Knows BAT-GO Group】
@echo off
::Set backup folder path
set bakpth=D:\UDISKBAK
If the :: variable type value is empty, all files on the USB flash drive are backed up by default. If only .RAR type files are backed up, set type=.RAR, and so on
set type=
:: Obtain the USB drive letter and perform the backup operation
for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
fsutil fsinfo drivetype %%a:|findstr "movable">Nul&&(set udisk=%%a&call :ucopy)
)
exit
:ucopy
if not exist "%bakpth%\%udisk%" md "%bakpth%\%udisk%"
::Copy the USB flash drive file, and the empty folder is not copied by default. If you need to copy the empty folder, change the downline command switch /s to /e
xcopy /s/h/y %udisk%:\*%type% "%bakpth%\%udisk%" >nul 2>nul
goto :eof