A question about a command inside a variable
Posted: 21 Apr 2019 04:59
Here is what I have.
Umodified script - works great
Modified script for readability - does not work
I would like to know:
Umodified script - works great
Code: Select all
SETLOCAL EnableDelayedExpansion
set "_wmic_command=wmic logicaldisk where "drivetype =2" get VolumeName^, FileSystem^, Description^, Caption"
set numOpts=0
FOR /f "usebackq skip=1 tokens=*" %%G IN (`%_wmic_command% ^| findstr /r /v "^$"`) DO (
set "line=%%G"
set /A numOpts+=1
echo !numOpts! !line!)
pause
Modified script for readability - does not work
I would like to know:
- Why this script currently do not work. What can be done to make it work.
- if this is good way to improve readability of my previous script, if it worked
- I put findstr /r /v $" into a variable _removeLastWmicLine
Code: Select all
@echo off
SETLOCAL EnableDelayedExpansion
set "_wmic_command=wmic logicaldisk where "drivetype =2" get VolumeName^, FileSystem^, Description^, Caption"
set "_removeLastWmicLine=findstr /r /v $"
set numOpts=0
FOR /f "usebackq skip=1 tokens=*" %%G IN (`%_wmic_command% ^| %_removeLastWmicLine%`) DO (
set "line=%%G"
set /A numOpts+=1
echo !numOpts! !line!)
pause