Detect USB and copy *.* to USB drive using batch script

前端 未结 4 718
野性不改
野性不改 2020-12-15 14:13

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 anoth

4条回答
  •  感动是毒
    2020-12-15 14:27

    The above code had a flaw which has been attended to in the following code The code works in XP and gives you the USB drive letters, if no usb device is connected , it tells you so !

    :: SUCCESS @ 2:39 AM ON 12 OCT 2013 !!! :: IMPROVED BY BOBBY GOREJA

    @echo off
    
    set usbdrv=
    set usb=No
    :: Above two lines on 12 Oct 2013
    
    fsutil fsinfo drives >de
    type de | find "Drives:" /v >dlist
    
    for /F "tokens=1" %%c in ('type dlist') do (
    
                   for /F "tokens=3" %%d in ('fsutil fsinfo drivetype %%c') do (
    
                   rem echo Token is %%d
    
                 if %%d equ Removable (
    
                echo Drive %%c is Removable (USB^)
    
                 set usbletter=%%c 
                 set usb=Yes
    
                echo USB drive letter is %usbletter%
    
    rem     set usbdrv = %%c   <<< this does NOT work!
     rem              echo USB1 drive letter is %usbdrv%
    
                                                                    )
                                             )
                                        )
     del de
     del dlist
    
                 echo  REPEAT:Device at %usbletter%
    
    if  "%usb%"=="No" echo No USB Device Connected .
    set usb=
    

提交回复
热议问题