Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Docfxit
- Posts: 132
- Joined: 12 Nov 2015 12:42
#1
Post
by Docfxit » 04 Dec 2019 19:15
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?
-
penpen
- Expert
- Posts: 2009
- Joined: 23 Jun 2013 06:15
- Location: Germany
#2
Post
by penpen » 04 Dec 2019 19:28
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
-
Docfxit
- Posts: 132
- Joined: 12 Nov 2015 12:42
#3
Post
by Docfxit » 04 Dec 2019 21:35
That worked perfect.
Thank you very very much,
Docfxit