i am looking for a way to save drive names into var
we can get the drive names using this
for %a in ( B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO @if exist %i: @echo %a:
now if the output is for exmaple
c
d
e
n
i want to do something like this
set drive1=C
set drive2=d
...
i came with one way
i can save the output in a text file and then using findstr serach for names and if find one save it in a var
but i want to know is there any better way?
also if we use a command like dir
can we serach for string without saveing the output in a text file?
i think i must use for /f perhaps?
saving drive names into variable
Moderator: DosItHelp
Re: saving drive names into variable
This should set the drives accordingly.
Code: Select all
@Echo Off & SetLocal EnableDelayedExpansion
Set _DRVNUM=0
For /f "Delims=: " %%A In ('Mountvol^|Find ":\"') Do (Set/a _DRVNUM +=1
Set Drive!_DRVNUM!=%%A)
Set Drive
Ping -n 6 127.0.0.1 1>Nul
Re: saving drive names into variable
Code: Select all
@echo off
for /f "tokens=2 delims==:" %%i in ('
wmic logicaldisk get Name /value
') do (
set %%i=%%i
call set %%%%i%%| findstr /x %%i=%%i
)
pause>nul
exit /b
???