Batch - Get a volume label to a variable

May 3, 2009 at 14:51:31
Specs: Windows XP
Hi All,

Writing a DOS script.
How can I get the volume label of a drive into a variable of a dos script?


See More: Batch - Get a volume label to a variable

Report •


#1
May 3, 2009 at 16:53:54
Here's one way...

:: Code begins...
@echo off
cls

for /f "tokens=1-5*" %%1 in ('vol') do (
    set volume=%%6 & goto echoit
)

:echoit
echo %volume%

:: Code ends...


Report •

#2
May 3, 2009 at 17:42:35
For dos or for xp?

for xp

for /f "tokens=5*" %%l in ('2^>nul vol c:^|find /v /i "Volume Serial Number is"^|find /v /i "has no label"') do set label=%%m


for dos (will depend on vol's output)

vol c: > temp1.bat
echo if "%%1"=="in" set label=%%5 > volume.bat
call temp1.bat
del volume.bat
del temp1.bat
echo %label%


Report •

#3
May 3, 2009 at 23:54:02
Cool Stuff!!

First one worked straight out of the box..

I use this var volume in the script =

title Copy to %volume%

Tile all the windows vertically or horizontally and it neatly lists all the devices that are active!

Thx from Amsterdam

Eric


Report •

Related Solutions


Ask Question