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 00:41
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » (Solved) How to get the drive letter of a USB flash drive in a DOS batch file? View 1,208 Replies 5
Original Poster Posted 2006-12-26 23:13 ·  中国 重庆 联通
初级用户
Credits 22
Posts 10
Joined 2006-09-08 02:55
19-year member
UID 62112
Status Offline
After booting a DOS boot disk made from a USB flash drive into MS-DOS7.1, on some machines its drive letter is “A:”, while on other machines its drive letter is “C:”.
In the batch file autoexec.bat on the USB flash drive, when the drive letter of the USB flash drive is “A:”, program A needs to be executed; when the drive letter of the USB flash drive is “C:”, program C needs to be executed.
How can I get the drive letter of the USB flash drive in the DOS batch file autoexec.bat to make this work?
Thanks in advance!

Solved using the method introduced in post #4.

Thanks again for the answers from the helpful members!

[ Last edited by chenqiguang on 2006-12-27 at 10:28 PM ]
Floor 2 Posted 2006-12-26 23:53 ·  中国 江西 宜春 樟树市 电信
新手上路
Credits 7
Posts 4
Joined 2005-10-16 10:58
20-year member
UID 43575
Gender Male
From 四川成都
Status Offline
I can't answer the OP's question.
But I can provide one method I use for reference:
In “autoexec.bat”, set the program execution path like this:
SET PATH=A:\dos_tool\;A:\;\C:\dos_tool\;C:\
After that, when executing a program, just write the program name directly.
For example:
LH CTMOUSE
LH DOSKEY
There is no need to call the program with an absolute path. That will do.
As for the reason for the difference between A and C drives, it is related to the way the bootable USB flash drive is made.
With the zip/FDD method, after booting it becomes drive A
With the HDD method, after booting it becomes drive C.
If anything is incomplete, you can contact me by E-mail for discussion.
zplinux@21cn.com
Floor 3 Posted 2006-12-27 00:22 ·  中国 重庆 联通
初级用户
Credits 22
Posts 10
Joined 2006-09-08 02:55
19-year member
UID 62112
Status Offline
The program to be executed needs parameters, so an absolute path must be used.
Floor 4 Posted 2006-12-27 03:48 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
You can put a signature file in the root directory of your USB flash drive and use it for detection.
Suppose the file is myudisk.000
if not exit a:\myudisk.000 goto c
a
goro exit

:c
c

:exit

[ Last edited by lianjiang2004 on 2006-12-27 at 03:50 AM ]
Windows 一键还原
http://www.yjhy.com
Floor 5 Posted 2006-12-27 05:09 ·  中国 重庆 联通
初级用户
Credits 22
Posts 10
Joined 2006-09-08 02:55
19-year member
UID 62112
Status Offline
Originally posted by lianjiang2004 at 2006-12-27 03:48:
You can put a signature file in the root directory of your USB flash drive and use it for detection.
Suppose the file is myudisk.000
if not exit a:\myudisk.000 goto c
a
goro exit

:c
c

:exit

[ Last edited by lianjiang2004 ...


I'll reply again after testing it.
Floor 6 Posted 2006-12-30 00:18 ·  中国 四川 成都 电信
初级用户
Credits 66
Posts 24
Joined 2006-12-14 01:18
19-year member
UID 73443
Gender Male
Status Offline
This problem is very simple. I also ran into it when making a bootable USB flash drive. The USB flash drive was originally ZIP, but some motherboards insist on recognizing it as drive C: after booting, so the drive letter of the boot disk has to be identified.
There are two methods:
1. Signature detection, FOR %%A IN (A: C:) DO IF EXIST DOS\DRIVERS\NUL SET BDR=%%A (DOS\DRIVERS is a directory on my USB flash drive)This way the boot drive letter can be set into the %BDR% variable.
2. Use a small tool: bootdrv.com. After running it, it will return an errorrlevel value, and by testing that you can know the boot drive letter.
Forum Jump: