Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello,
I am trying to get a BAT file to perform specific cleanup based on the volume label. I think I am getting close, but can't quite seem to get it 100%. Here is what I am trying so far:
:YesClean echo This is where the prior boot cleanup will occur based on volume label for /f "tokens=1-5*" %%1 in ('vol') do (set volume=%%6 & goto cleanup) :cleanup if /i %volume% EQU "TEST" goto TEST :FAILURE echo This catches if the volume check has failed Goto END :TEST echo This is where actions needed based on volume label would occur :END echo That's AllI keep ending up in the FAILURE section despite the volume name being TEST and showing such if I echo it. Any help would be greatly appreciated.
Chris

if /i "%volume%" EQU "TEST" goto TEST
If that doesn't work, keep echo on, and show us the output for the line.

You better look at your VOL output. Mine is:
========================
Volume in drive C is 2G_40
Volume Serial Number is 3318-1605
==============================
If yours is similar, you'll probably need:
=====================================
@echo off & setLocal enableDELAYedexpansionfor /f "tokens=1-5* delims= " %%a in ('vol') do (
set v=%%f
goto :done here
)
:done here
echo label is !v!
=====================================
Helping others achieve escape felicityM2

Hello,
I can't believe I didn't think to ECHO the info as Razor2.3 noted. What I discovered is that I am getting a space after the volume name that is being captured as a variable. Now that I know that I am just adding a space to the name being looked for in the IF statement and all is working well.
Thanks for the help,
Chris

set volume=%%6 & goto cleanup)
That's where you're getting the space.
=====================================
Helping others achieve escape felicityM2

Hi Mechanix2Go,
Thanks for the info, but I am not sure how to remove the extra space it based on your reply. Sorry if I am missing something and adding the space to the volume name being compared works, but I wouldn't argue with learning why it is happening if you are willing to share.
Thanks,
Chris

set volume=%%6& goto cleanup)
=====================================
Helping others achieve escape felicityM2

the reason might possibly be:
there is one space output by "vol" after the volume label, as you observed. using delims= "and tokens=5* causes the space to be appended to last token since token 5 mops up the balance of the inputline from "vol". removal of asterisk from "tokens=" clause might fix, or set tokens to: 1-6 and put asterisk on number 6.
it's all academic for this issue however.

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |