Batch file to convert volume name to drive letter

D

danielm

Since I did not see this done anywhere in a simple way I've written
this up .

Feel free to improve.
danielm A@T citenet DOT net



[START OF FILE]=====================================================

@Echo off
REM File created by danielm@ci***et.net. Daniel Moscovitch.
2007/03/31 . Version 1.0#
REM FOR NON COMMERCIAL USE ONLY. Email for other uses.
REM Please credit if used and email me if you've improved it :)
REM
REM ONLY FOR WINDOWS XP. Requires Administrative rights as far as I
know for diskpart.exe command.
REM This script will find and return the drive letter of the drive
that matches the NAME given.
REM In this case "FLASHHDD" . This volume name should be very uniq and
not short, to avoid mistakes.
REM If your Volumename matches more than one text entry in the volume
dump it will choose the last matching drive entry.
REM Change the name "FLASHHDD" to what you want as volume name of your
device
REM Volume name can be supplied on command line. 1 word only. Test
with something randome to see list.

REM Create the script file for diskpart
echo list volume > VOLLIST.SCP

REM This runs the script and outputs the data to that file.
IF %1.==. (
diskpart /s VOLLIST.SCP | find /i "FLASHHDD" > VOLLIST.TXT
) ELSE (
diskpart /s VOLLIST.SCP | find /i "%1" > VOLLIST.TXT
)

REM Setup evironment variable for drive letter.
SET FLASHDRIVE=
For /F " tokens=3 " %%I in (VOLLIST.TXT) do SET FLASHDRIVE=%%I:
if NOT DEFINED FLASHDRIVE goto NOTFOUND

REM ***************** ***************** *****************
***************** *****************
REM YOUR COMMANDS GO HERE!!!!!! Using %FLASHDRIVE%. ie. Dir
%FLASHDRIVE% .
echo TEST My Flashdrive is on drive %FLASHDRIVE%
echo %FLASHDRIVE%
pause
REM ***************** ***************** *****************
***************** *****************

GOTO CLEANUP

:NOTFOUND
ECHO ***DRIVE VOLUME NOT FOUND. Here is a list...
diskpart /s VOLLIST.SCP
pause

:CLEANUP
del VOLLIST.SCP
del VOLLIST.TXT
SET FLASHDRIVE=

:END


[END OF FILE]=====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top