USB Drive

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Jamessotech
Posts: 3
Joined: 23 Oct 2014 13:24

USB Drive

#1 Post by Jamessotech » 23 Oct 2014 13:40

I am trying to write batch file that will recognize a thumb drive and assign drive letter automatically.
For installing a program from the drive. I have tried a couple from the internet but they do not recognize my thumb drive.

This is one I tried:

Code: Select all

set "USBDRV="
for %%a in (d e f g h i j k l m n o p q r s t u v w x y z) do (
if exist "%%a:\$Emergency Plan 2014\" set USBDRV=%%a
)
if not defined USBDRV echo THE USB DRIVE WASN'T FOUND & pause&goto :EOF
echo copying Emergency Plan 2014 to Desktop
RD /s /q "%USBDRV%:\$Emergency Plan 2014"
xcopy   "%USBDRV%:\JCSO Emergency Plan 2014 v. 200.exe\" to "C:\Emergency Plan 2014\" /s /c
pause


It seems to be looking for the thumb drive but it stops searching at "H" and the drive assigned by computer is "J",
any help will be appreciated.
:?:

MOD EDIT: Added Code Tags.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: USB Drive

#2 Post by Squashman » 23 Oct 2014 14:02

Are you running the batch file from the USB drive?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: USB Drive

#3 Post by foxidrive » 23 Oct 2014 14:36

Code: Select all

set "USBDRV="
for %%a in (d e f g h i j k l m n o p q r s t u v w x y z) do (
echo searching on drive %%a:
if exist "%%a:\$Emergency Plan 2014\" set USBDRV=%%a
)
if not defined USBDRV echo THE USB DRIVE WASN'T FOUND & pause&goto :EOF
echo copying Emergency Plan 2014 to Desktop
RD /s /q "%USBDRV%:\$Emergency Plan 2014"
xcopy   "%USBDRV%:\JCSO Emergency Plan 2014 v. 200.exe\" to "C:\Emergency Plan 2014\" /s /c
pause


It seems to be looking for the thumb drive but it stops searching at "H" and the drive assigned by computer is "J",
any help will be appreciated.
:?:


Try the above - and make sure that \$Emergency Plan 2014\ is not located on drive H:

Post Reply