The problem arises like this.
I saw someone wrote an example of judging the CD - ROM:
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
The above method is very simple, but there is a problem. That is, when there is no CD - ROM in the optical drive, an error message will pop up, and then the subsequent commands cannot be executed. What's worse, if there are two optical drives and the CD - ROM is in the second optical drive, the result cannot be obtained at all because the first optical drive cannot be read and the second optical drive cannot be detected.
So I used the Dready small program. The usage of this small program is Dready /w, which returns errorlevel 0, 1, 2, 255. If it returns 1, it means it is Readonly, that is, it means this is an optical drive and it is ready.
I modified the program:
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 Dready %%i &if errorlevel 1 echo %%i>>cdrom.txt
My idea is to first detect the readable optical drives into a temporary file, and then use the For command again to detect the file WIN51 in the optical drive. The second step is easy to compile. The problem is in the first step above.
The result of the cdrom.txt file is not what I expected because the value of errorlevel has always been the value of the last detected optical drive. I think this is the problem of delayed variables.
So I added setlocal ENABLEDELAYEDEXPANSION in the program and used!errorlevel! instead of %errorlevel%, but I actually found that!errorlevel! is not a value but!errorlevel! itself.
Finally, I simply compiled a program as follows:
setlocal ENABLEDELAYEDEXPANSION
set test="No problem"
echo !test!
The actual running result is not No problem, but!test!, what's the matter?
When I copied the example, it was correct. When I compiled it myself, it was wrong, and it's not the problem of full - width and half - width. I still have this knowledge.
In order to avoid mistakes, many sentences are copied. I just wrote set = xxx myself, but it's wrong. I can't figure it out.
Please help me, thank you!
[ Last edited by quya on 2008 - 5 - 29 at 12:41 PM ]
I saw someone wrote an example of judging the CD - ROM:
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
The above method is very simple, but there is a problem. That is, when there is no CD - ROM in the optical drive, an error message will pop up, and then the subsequent commands cannot be executed. What's worse, if there are two optical drives and the CD - ROM is in the second optical drive, the result cannot be obtained at all because the first optical drive cannot be read and the second optical drive cannot be detected.
So I used the Dready small program. The usage of this small program is Dready /w, which returns errorlevel 0, 1, 2, 255. If it returns 1, it means it is Readonly, that is, it means this is an optical drive and it is ready.
I modified the program:
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 Dready %%i &if errorlevel 1 echo %%i>>cdrom.txt
My idea is to first detect the readable optical drives into a temporary file, and then use the For command again to detect the file WIN51 in the optical drive. The second step is easy to compile. The problem is in the first step above.
The result of the cdrom.txt file is not what I expected because the value of errorlevel has always been the value of the last detected optical drive. I think this is the problem of delayed variables.
So I added setlocal ENABLEDELAYEDEXPANSION in the program and used!errorlevel! instead of %errorlevel%, but I actually found that!errorlevel! is not a value but!errorlevel! itself.
Finally, I simply compiled a program as follows:
setlocal ENABLEDELAYEDEXPANSION
set test="No problem"
echo !test!
The actual running result is not No problem, but!test!, what's the matter?
When I copied the example, it was correct. When I compiled it myself, it was wrong, and it's not the problem of full - width and half - width. I still have this knowledge.
In order to avoid mistakes, many sentences are copied. I just wrote set = xxx myself, but it's wrong. I can't figure it out.
Please help me, thank you!
[ Last edited by quya on 2008 - 5 - 29 at 12:41 PM ]
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.

