中国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-18 18:59
47,814 topics / 349,908 posts / today 1 new / 48,259 members
DOS批处理 & 脚本技术(批处理室) » In DOS, how to determine the drive letter of the last partition of the hard disk; how to judge the directory
Printable Version  2,049 / 11
Floor1 zhamin Posted 2006-03-05 23:50
新手上路 Posts 1 Credits 6
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.
Floor2 lks205 Posted 2006-03-11 11:00
初级用户 Posts 32 Credits 86
I also want to know the answer
Floor3 baomaboy Posted 2006-03-11 12:58
银牌会员 Posts 554 Credits 1,513
I want to know too
Floor4 chenall Posted 2006-03-11 16:28
银牌会员 Posts 469 Credits 1,276 From 福建泉州
Floor5 kpc163 Posted 2006-03-11 23:08
初级用户 Posts 9 Credits 22
『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
Floor6 floor Posted 2006-03-12 01:21
初级用户 Posts 82 Credits 185
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
Floor7 chenall Posted 2006-03-12 12:31
银牌会员 Posts 469 Credits 1,276 From 福建泉州
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.
Floor8 3742668 Posted 2006-03-12 21:09
荣誉版主 Posts 718 Credits 2,013
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 ]
Floor9 Climbing Posted 2006-03-13 00:31
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
If the system is set with a memory virtual disk during startup, then all the above programs will become invalid.
Floor10 lks205 Posted 2006-03-13 13:46
初级用户 Posts 32 Credits 86
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!
Floor11 3742668 Posted 2006-03-13 20:09
荣誉版主 Posts 718 Credits 2,013
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.
Floor12 floor Posted 2006-03-14 02:01
初级用户 Posts 82 Credits 185
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
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023