U disk data backup batch code

Time:2020-6-27

explain:
1. Automatically detect all removable disks (if applicable to floppy disks, please add two letters A and B in for statement)
2. All files in the default backup disk can be modified to backup a specified type of file according to the notes
3、 Please modify the backup folder path before use
4. For other precautions, please refer to the notes in the code

The batch code is as follows:

Copy codeThe code is as follows:
:: 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 in the U disk will be backed up by default. If only files of type. Rar are backed up, then set type =. Rar, and so on
set type=
:: get the U-disk 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 “mobile” > nul & & (set Udisk =%% a & Call: Ucopy)
)
exit

:ucopy
if not exist “%bakpth%\%udisk%” md “%bakpth%\%udisk%”
:: copy the U disk file. By default, do not copy the empty folder. If you need to copy the empty folder, change the down command switch / s to / E
xcopy /s/h/y %udisk%:\*%type% “%bakpth%\%udisk%” >nul 2>nul
goto :eof