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-07-02 01:27
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » I saw this bit of code on this forum, but I don't know what the principle behind it is? View 686 Replies 4
Original Poster Posted 2007-12-29 11:20 ·  中国 河北 邯郸 电信
初级用户
Credits 30
Posts 12
Joined 2007-10-19 18:07
18-year member
UID 100183
Gender Male
Status Offline
@echo off
for %%i in (Z Y X W V U T S R Q P L O N M L K J I H G F E D C ) do (
if exist %%i:\nul echo The last drive letter is %%i & pause>nul && goto :eof
)
This can determine what the last drive letter is—what is the principle behind it?
Thanks
Floor 2 Posted 2007-12-29 12:09 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
It loops in order from Z down to C. Note that this is in reverse order, so if the if statement detects that a certain drive letter is available, it displays that drive letter and exits, so it can basically determine the last drive letter.
Floor 3 Posted 2007-12-29 20:30 ·  中国 河北 邯郸 临漳县 电信
初级用户
Credits 30
Posts 12
Joined 2007-10-19 18:07
18-year member
UID 100183
Gender Male
Status Offline
Then what is the function of NUL here?
Floor 4 Posted 2007-12-31 22:58 ·  中国 安徽 马鞍山 电信
中级用户
★★
拟谷盗
Credits 312
Posts 108
Joined 2007-01-21 11:36
19-year member
UID 77238
Gender Male
Status Offline
@echo off
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:\ echo %%i
pause>nul


>nul means the output is empty
Example: ping 127.1 >nul
This pings the loopback address 127.0.0.1, but the execution result is not displayed on the screen

There is also >nul 2>nul
This means suppressing error output


In batch files, “>nul” is often used together with “@” and “@echo off” to keep ordinary users from seeing any information.
Floor 5 Posted 2008-01-01 10:10 ·  中国 江苏 无锡 电信
初级用户
Credits 52
Posts 21
Joined 2008-01-01 09:30
18-year member
UID 107370
Gender Male
Status Offline
For example, con stands for the display device, prn stands for the printing device, and nul stands for the null device.
The greater-than sign ">" means redirecting the output of the preceding program to the device after the ">". For example,
type a.txt means displaying the contents of a.txt on the screen,
while type a.txt > prn means sending the contents of a.txt to the printer (similar to copy a.txt prn)
pause >nul means executing the pause command, but not displaying the pause prompt
c:\nul is the same as c:\
Forum Jump: