简体   繁体   中英

How to rename part of the volume label in a batch file

I am creating a batch file to change some things on a Windows XP embedded machine (copy files, change registry settings). One of the things is to change the volume label from

"AAA BBBB vX.X"

to

"CCC DDD vX.X"

where 'vX.X' is a version number that has to stay the same (eg v1.23).

How can I do it in a batch file?

If your volume name has always exactly this shape (SOMETHING SOMETHING SOMETHING) you can try this:

@ECHO OFF
FOR /F "tokens=8 delims= " %%G IN ('vol') DO SET lastToken=%%G
LABEL C: CCC DDD %lastToken%

tokens=8 will give you the third token of the volume name (split by whitespace) - in your case vX.X.

tokens=6 would be AAA and tokens=7 BBBB.

Obvoiusly this code only works in you are on drive C: and you want to rename drive C: . If you want to rename D: just add D: as new line just below @ECHO OFF and change C: to D: in the last line and so on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM