China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-09-28 08:32
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Seeking Improvement] A New Method to Judge the CD-ROM Drive View 3,161 Replies 17
Floor 16 Posted 2008-05-28 22:13 ·  中国 江苏 苏州 常熟市 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
There are still some questions to ask.

It is said that the fsutil command can only be restricted to be used by administrators, and only the XP Pro version can be used.

The dir [drive] >nul 2>nul is too useful.

But do we have to go back to the old way of for %%i in (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\WIN51 set CDROM=%%i? There is a defect in this old way, that is, it is necessary to judge a specific file. Is there a better way?
Floor 17 Posted 2008-05-28 23:08 ·  中国 江苏 苏州 常熟市 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
According to the idea of 26933062, I made one

@echo off&setlocal EnableDelayedExpansion
for /f "usebackq skip=1 tokens=2 delims==" %%a in (`findcd /s`) do (
set "str=%%a"
set "str=!str:~0,1!"
dir !str!: >nul 2>nul
chcp 936>nul
if !ERRORLEVEL! equ 0 (echo.&echo The CD is drive !str! and there is a CD inside) else (
echo.&echo The CD is drive !str! and there is no CD
))
echo.&pause&exit


Explanation: findcd.exe is a third-party program, only 3.11K

If this program findcd is added with the /s parameter, it will list multiple CDs, and the result is as in the following example:

CDROM=2
CDROM1=H:
CDROM2=I:

Under old DOS, these variables will be assigned, saving a lot of trouble, but under XP, it can't! And it will change the codepage, so I added a line CHCP 936.

The actual running result is as follows:

The CD is drive 2 and there is a CD inside

The CD is drive H and there is a CD inside

The CD is drive I and there is a CD inside

Press any key to continue...


Why is there an extra line, it seems that skip=1 is useless, I don't understand.

Why can't I insert an attachment? I want to attach the program of findcd. Download here

[ Last edited by quya on 2008-5-28 at 11:29 PM ]
Floor 18 Posted 2008-05-29 19:34 ·  中国 重庆 电信
初级用户
★★
Credits 198
Posts 89
Joined 2007-09-06 23:22
19-year member
UID 96746
Gender Male
From 重庆
Status Offline
%var1%^|more
%var2% %%a:
This trick in floor 11 looks very neat!

[ Last edited by WANKOILZ on 2008-5-29 at 07:38 PM ]
Forum Jump: