中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-19 05:03
47,814 topics / 349,908 posts / today 1 new / 48,259 members
DOS疑难解答 & 问题讨论 (解答室) » I saw this bit of code on this forum, but I don't know what the principle behind it is?
Printable Version  726 / 4
Floor1 handan Posted 2007-12-29 11:20
初级用户 Posts 12 Credits 30
@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
Floor2 lxmxn Posted 2007-12-29 12:09
版主 Posts 4,938 Credits 11,386
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.
Floor3 handan Posted 2007-12-29 20:30
初级用户 Posts 12 Credits 30
Then what is the function of NUL here?
Floor4 ngd Posted 2007-12-31 22:58
中级用户 Posts 108 Credits 312
@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.
Floor5 everdos Posted 2008-01-01 10:10
初级用户 Posts 21 Credits 52
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:\
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023