Page 1 of 1

Show drive letter of DVD drive

Posted: 04 Dec 2019 19:15
by Docfxit
I would like to find the drive letter of the DVD drive.
With this code in a batch file running in Win7
The Echo %%1 is not showing the drive
The line Set DVDDrive=%%1 is showing %1 instead of the drive letter.

Code: Select all

setlocal
for /f "skip=1 tokens=1,2" %%i in ('wmic logicaldisk get caption^, drivetype') do (
  if [%%j]==[5] echo %%i
  )
endlocal
Set DVDDrive=%%1
Echo DVDDrive = %DVDDrive%
How can this code be changed to show the drive letter?

Re: Show drive letter of DVD drive

Posted: 04 Dec 2019 19:28
by penpen
I assume the for/f loop you are using already determines your dvd drive encapsulating it in the %%i for-variable.
So just use store that value to an environment variable and use that befor your "endlocal" (which restores the
variables to a prior state; untested):

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion
for /f "skip=1 tokens=1,2" %%i in ('wmic logicaldisk get caption^, drivetype') do (
	if [%%j]==[5] Set DVDDrive=%%i
)
echo(DVDDrive = %DVDDrive%
endlocal

goto :eof
penpen

Re: Show drive letter of DVD drive

Posted: 04 Dec 2019 21:35
by Docfxit
That worked perfect.

Thank you very very much,

Docfxit