USB Drive letter [Solved]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

USB Drive letter [Solved]

#1 Post by abc0502 » 12 Jul 2012 03:21

I'm using this code to get the usb drive letter using the serial number, but while it rune it give me a message that apath is not exist because using druve letter not exist so is there a way to suppress this messages so it give the usb letter only

Code: Select all

@Echo off
Cls
setlocal
For %%A in (C D E F G H I J K L M N) Do (
      for /f "tokens=5 delims= " %%B in ('Vol %%A:') Do (
            if %%B==C073-25E8 set drv=%%A
      )
)
echo %drv%
pause
Last edited by abc0502 on 12 Jul 2012 03:39, edited 1 time in total.

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

Re: USB Drive letter

#2 Post by foxidrive » 12 Jul 2012 03:36

Try this maybe:

Code: Select all

@Echo off
Cls
setlocal
set drv=not found
For %%A in (C D E F G H I J K L M N) Do (
      if exist "%%A:\" (for /f "tokens=5 delims= " %%B in ('Vol %%A:') Do if %%B==C073-25E8 set drv=%%A)
)
echo %drv%
pause

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: USB Drive letter

#3 Post by abc0502 » 12 Jul 2012 03:37

That is Perfect Thanks Foxi :D

Post Reply