Solved Display all defined variables

November 2, 2012 at 00:58:38
Specs: Windows 7
I've got a script which counts the number of drives and parses them to a variable.
@echo off & setlocal enabledelayedexpansion
set counter=-2
for /f "delims=" %%a in ('wmic logicaldisk get name') do (
set /A counter+=1
set drives=!drives!%%a
set drives=%drives:~6%
set drives=%drives:~0,-4%
for /f "tokens=1-%counter% delims= " %%a in ('echo %drives%') do (
set first=%%a
set second=%%b
set third=%%c
echo.Number of drives:%counter%
pause > nul
exit /b

Now i've got a minor problem which would result in messy code. I want after the last for command to output all drives in this format
Now the issue is how would i only output all the drives that are currently connected to each variable without using if defined on each line? e.g if defined %%c set 3=%%c So say if the number of drives was 5, the output would be
An idea i just came up with would be a loop with the number of drives in total/the limit and output all that until x limit is met.

See More: Display all defined variables

Report •

November 2, 2012 at 02:00:50
✔ Best Answer
:: ===== script starts here ===============
:: drives.bat 2012-11-02 15:45:05.17
@echo off & setLocal enableDELAYedeXpansioN

set N=

for /f "skip=1 delims=" %%a in ('wmic logicaldisk get name') do (
set /a N+=1
set D!N!=%%a
set D
::====== script ends here =================

Life is too important to be taken seriously.


Report •

November 2, 2012 at 02:03:27
Nvm fixed thanks to machanix2go this can be considered as solved.

Report •
Related Solutions

Ask Question