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-08-15 14:29
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » [Detailed Explanation] Cleverly Getting the Last Hard Disk Drive Letter under Pure DOS View 1,623 Replies 3
Original Poster Posted 2009-10-12 15:45 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,284
Posts 538
Joined 2002-11-02 00:00
23-year member
UID 129
Gender Male
Status Offline
I’m forgetful, so I’m posting this. On one hand it’s convenient for others, and on the other hand I’m making notes for myself.

Required tools:
http://upload.cn-dos.net/img/1715.rar

Included files:
COUNT.COM
COUNT.TXT
HDRIVE.EXE
NSET.COM
NSET.TXT

Feature: does not generate (third-party) files

Complete example:
SET NUM=25
:CHECK
COUNT.COM NUM -
HDRIVE.EXE|NSET.COM LASTPART=$%NUM%
IF "%LASTPART%"=="" GOTO CHECK


HDRIVE.EXE is used to get recognizable hard disk drive letters. When a hard disk partition format is not FAT32, it cannot recognize it. For example, suppose the current hard disk partitions are as follows:
C:FAT32
D:FAT32
E:NTFS
F:FAT32
Run: C:\>HDRIVE.EXE and press Enter, then it returns:
C:
D:
E:
The original E:cannot be recognized, so F:takes its place. That means the E:here is the F:drive under Windows.

The function of NSET.COM is to define the passed parameters as its self-recognized $?, and it can also define variables.
For example: HDRIVE.EXE|NSET.COM LASTPART=$%NUM%
HDRIVE.EXE passes the parameters C:D:E:to NSET.COM, which means:
C: D: E:
$1 $2 $3
LASTPART=$%NUM%
When the value of NUM is 4, then LASTPART=empty (empty means if this variable exists, then delete this variable)
When the value of NUM is 3, then LASTPART=E:

Why define NUM=25? Because the loop first subtracts 1 from it (improved after a reminder from 523066680)

Because hard disk drive letters are counted starting from C:, 24 represents the Z:drive letter.

COUNT.COM is used to perform arithmetic on the value of a numeric variable
COUNT.COM NUM - means subtract 1 from the value of the variable

IF "%LASTPART%"=="" GOTO CHECK
When the value of the variable LASTPART is empty, that means the number for the last drive letter has not yet been reached, so it loops, until the value of NUM is 3, at which point the value represented by $3, E:, is assigned to the variable LASTPART. At that time LASTPART is no longer empty, and the loop ends.

[ Last edited by chishingchan on 2009-10-19 at 12:55 ]
Floor 2 Posted 2009-10-12 17:54 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
hi ~ this is the first time I’ve seen you post in 2009.
Do you still remember me~

http://www.cn-dos.net/forum/viewthread.php?tid=39780

What you said there really encouraged me ^_^
-----------------------------------------


By the way, you said it is counted starting from C, so shouldn’t Z be 26?

[ Last edited by 523066680 on 2009-10-12 at 17:59 ]
Floor 3 Posted 2009-10-12 22:28 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,284
Posts 538
Joined 2002-11-02 00:00
23-year member
UID 129
Gender Male
Status Offline
Originally posted by 523066680 at 2009-10-12 05:54 PM:
By the way, you said it is counted starting from C, so shouldn’t Z be 26?...


Right! Thanks for the reminder! I can’t believe such a low-level mistake happened to me. Haha!

Can’t help it! I’ve got too many projects! What I’m into now is VBS. I only research DOS when I need to use it now, so I get forgetful, and that’s why I posted this mistaken article!
Floor 4 Posted 2009-10-13 20:54 ·  中国 浙江 金华 永康市 电信
初级用户
Credits 29
Posts 16
Joined 2007-09-20 14:49
18-year member
UID 97887
Gender Male
Status Offline
It would be even better to add a batch file for getting the last hard disk drive letter under pure DOS
Forum Jump: