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-01 06:15
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » In DOS, how to determine the drive letter of the last partition of the hard disk; how to judge the directory View 1,915 Replies 11
Original Poster Posted 2006-03-05 23:50 ·  中国 广东 珠海 香洲区 电信
新手上路
Credits 6
Posts 1
Joined 2006-03-05 23:49
20-year member
UID 51432
Status Offline
Under the condition of having only one CD-ROM drive, FINDCD can be used to determine the drive letter of the CD-ROM drive. How to determine the drive letter of the last partition of the hard disk (excluding NTFS partitions) according to this drive letter? When creating a directory name, and how to determine whether the directory name exists? Please experts answer.
Floor 2 Posted 2006-03-11 11:00 ·  中国 福建 泉州 电信
初级用户
Credits 86
Posts 32
Joined 2006-01-27 15:56
20-year member
UID 49579
Status Offline
I also want to know the answer
Floor 3 Posted 2006-03-11 12:58 ·  中国 江苏 南京 电信
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
I want to know too
Floor 4 Posted 2006-03-11 16:28 ·  中国 福建 泉州 石狮市 电信
银牌会员
★★★
Credits 1,276
Posts 469
Joined 2002-12-23 13:00
23-year member
UID 586
Gender Male
From 福建泉州
Status Offline
Floor 5 Posted 2006-03-11 23:08 ·  中国 广东 江门 台山市 电信
初级用户
Credits 22
Posts 9
Joined 2006-03-01 20:52
20-year member
UID 51189
Status Offline
『Post #5』:

OK, just now I added an option /L to FINDCD to display and set the drive letter before the first CD-ROM to %CDROM%. Let's give it a try:
Open the attachment
For example, suppose the CD-ROM is D:
FINDCD /L
CDROM=C:

Attachment cannot be downloaded
Floor 6 Posted 2006-03-12 01:21 ·  中国 北京 大兴区 联通
初级用户
★★
Credits 185
Posts 82
Joined 2005-08-12 13:41
20-year member
UID 41586
Gender Male
Status Offline
Use the following method

func -a6>list.txt // Write all partition drive letters to list.txt (excluding CD-ROM drives)
STRINGS a=LINESIZE list.txt // Return the total number of lines in the file content
STRINGS p=READ list.txt,%a% // Read the content of the specified line in the file
echo %p% // %p% is the drive letter of the last partition
Floor 7 Posted 2006-03-12 12:31 ·  中国 福建 泉州 电信
银牌会员
★★★
Credits 1,276
Posts 469
Joined 2002-12-23 13:00
23-year member
UID 586
Gender Male
From 福建泉州
Status Offline
There is another method, you can try.
Use MD
if exist to judge the drive letter of the last partition.
You can try the following method.

@echo off
set drv=c d e f g h i j k l m n o p q r s t u v w x y z
if "%1"=="" if "%last_drv%"=="" call %0 %drv%
:set_last
if "%1"=="" goto end
md %1:\last.drv>nul
if not exist %1:\last.drv\nul goto end
rd %1:\last.drv>nul
set last_drv=%1:
shift
goto set_last

:end
QQ:366840202
http://chenall.net
Floor 8 Posted 2006-03-12 21:09 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
It all looks quite impressive. Let's do one too:

@echo off
cd\
set c=C:
set d=D:
set e=E:
set f=F:
set g=G:
set h=H:
set i=I:
set j=J:
set k=K:
set l=L:
set m=M:
set n=N:
set o=O:
set p=P:
set q=Q:
set r=R:
set s=S:
set t=T:
set u=U:
set v=V:
set w=W:
set x=X:
set y=Y:
set z=Z:

%c%
%d%
%E%
%f%
%g%
%h%
%i%
%j%
%k%
%l%
%m%
%n%
%o%
%p%
%q%
%r%
%s%
%t%
%u%
%v%
%w%
%x%
%y%
%z%

if "%cd%" == "%d%\" %c%
if "%cd%" == "%e%\" %d%
if "%cd%" == "%f%\" %e%
if "%cd%" == "%g%\" %f%
if "%cd%" == "%h%\" %g%
if "%cd%" == "%i%\" %h%
if "%cd%" == "%j%\" %i%
if "%cd%" == "%k%\" %j%
if "%cd%" == "%l%\" %k%
if "%cd%" == "%m%\" %l%
if "%cd%" == "%n%\" %m%
if "%cd%" == "%o%\" %n%
if "%cd%" == "%p%\" %o%
if "%cd%" == "%q%\" %p%
if "%cd%" == "%r%\" %q%
if "%cd%" == "%s%\" %r%
if "%cd%" == "%t%\" %s%
if "%cd%" == "%u%\" %t%
if "%cd%" == "%v%\" %u%
if "%cd%" == "%w%\" %v%
if "%cd%" == "%x%\" %w%
if "%cd%" == "%y%\" %x%
if "%cd%" == "%z%\" %y%

Tested in the command line and it works. Assume there's a disk in the CD-ROM and it can be accessed in the command line. The reason for writing it so long is to make it easy to execute under DOS. Not sure if there's the %cd% environment variable under DOS. Bored friends, help test it under DOS and pay attention to the case of the statements.

[ Last edited by 3742668 on 2006-3-12 at 22:49 ]
Floor 9 Posted 2006-03-13 00:31 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
If the system is set with a memory virtual disk during startup, then all the above programs will become invalid.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 10 Posted 2006-03-13 13:46 ·  中国 福建 泉州 电信
初级用户
Credits 86
Posts 32
Joined 2006-01-27 15:56
20-year member
UID 49579
Status Offline
Originally posted by Climbing at 2006-3-13 00:31, Climbing **Content**: If the system sets up a memory virtual disk during startup, all the above programs will become invalid.
Then it's all in vain, a false alarm!
Originally posted by Climbing at 2006-3-13 00:31:
If the system sets up a memory virtual disk during startup, all the above programs will become invalid.
Then it's all in vain, a false alarm!
Floor 11 Posted 2006-03-13 20:09 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Haha, the two upstairs are really funny.
I will only think you are awesome if you can provide a perfect solution.
Otherwise, just go stay aside.
Floor 12 Posted 2006-03-14 02:01 ·  中国 北京 大兴区 联通
初级用户
★★
Credits 185
Posts 82
Joined 2005-08-12 13:41
20-year member
UID 41586
Gender Male
Status Offline
Originally posted by Climbing at 2006-3-13 00:31:
If the system sets up a memory virtual disk during startup, then all the above programs will become invalid.


It's okay if the virtual memory disk is set up, because the total number of lines returned by strings is always one less than the actual number of lines, and the total number of lines obtained by "strings read file" returns the content of the second-to-last line, which is exactly the answer this question wants. As for why the last line is not read with the total number of lines it returns, I haven't figured it out yet, heh heh.

Output format of func -a6:

C
D
E
.
.
.
X :: X is the virtual memory disk letter
Forum Jump: