根据26933062思路, 我做了个
@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 光盘是 !str! 盘 里面有光盘) else (
echo.&echo 光盘是 !str! 盘 无光盘
))
echo.&pause&exit
说明: findcd.exe 是第三方程序,只有3.11K
这个程序 findcd 如果加 /s 参数则列出多光盘,结果如下例:
CDROM=2
CDROM1=H:
CDROM2=I:
在老DOS下 会赋值给上述变量, 省却许多麻烦, 但在XP下却不能!而且会改变 codepage, 所以我加了条 CHCP 936。
实际运行结果如下:
光盘是 2 盘 里面有光盘
光盘是 H 盘 里面有光盘
光盘是 I 盘 里面有光盘
请按任意键继续. . .
怎么会多了一行,似乎 Skip=1 没用处,不解。
怎么没办法插入附件? 我想附上 findcd的程序。
这儿下载
Last edited by quya on 2008-5-28 at 11:29 PM ]
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 ]