Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to write a batch file that will look at the volume label of the current drive and report if it's not equivalent to a certain string.

Is there a default variable in the shell for this? Can I define one? Am I SOL and I'll actually have to do some (shudder) programming?

EDIT: If this is possible in PowerShell that would work fine.

(For the curious, we ship our machines with software cloning as a rapid bootable backup solution since most of our customers are daytraders and aren't interested in RAID due to urgency of getting-the-hell-back-to-work-right-away if there's a software corruption problem, and we want to make it immediately obvious if they're booting to the backup drive unintentionally, like say the primary failed entirely. The hope was just to write a simple batch file that would autostart on boot and throw a warning in the event of a problem.)

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Give this a try:

for /f "tokens=6" %t in ('vol') do @set volid=%t
echo %volid%

Tip from the comments:

If it's in a batch file you need to double the %:

for /f "tokens=6" %%t in ('vol') do @set volid=%%t
share|improve this answer
    
Doesn't work. Getting 't was unexpected at this time'. The syntax looks right though... –  Shinrai Mar 11 '11 at 16:15
    
@Shinrai: If it's in a batch file you need to double the %: for /f "tokens=6" %%t in ('vol') do @set volid=%%t. –  Dennis Williamson Mar 11 '11 at 16:18
    
Doh, I thought that but I missed the second one when I tried. Works great, thanks, much more elegant than anything I could have done. I'm lousy at this, can you tell? –  Shinrai Mar 11 '11 at 16:23
    
@Shinrai: Believe me, it's not you that's lousy. It's really misfeatures of CMD that are lousy. –  Dennis Williamson Mar 11 '11 at 16:28
    
I was thinking of doing largely the same thing but piping it to a text file and doing a find against it. >.< But yeah, it's a crummy shell, even I know that! –  Shinrai Mar 11 '11 at 16:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.