【发布时间】:2015-07-21 08:46:22
【问题描述】:
我一直在努力编写一个脚本,该脚本将从驱动器的其他属性中找到驱动器索引号。脚本如下:
@echo off
REM batch file to load Veracrypt
Set "driveIndex="
for /f "skip=1 tokens=1 delims= " %%a in ('wmic diskdrive where "model ='WD Elements 1078 USB Device'" get index') do SET driveIndex=%%a & goto reportLetter
:reportLetter
if not defined driveIndex (
echo Error Occured!
pause
exit
) else (
echo \Device\Harddisk%driveIndex:~0%\Partition3
pause
exit
)
但是,脚本的输出是\Device\Harddisk1 \Partition3。我尝试了很长时间,但可以让脚本给出以下输出:\Device\Harddisk1\Partition3。
谁能告诉我如何更正代码以获得所需的输出?
【问题讨论】:
-
问题是 wmic 正在输出一个额外的空白行。
标签: regex windows batch-file batch-processing