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-06-25 08:26
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Seek a method to get the directory where the currently executing bat file is located. View 13,076 Replies 20
Floor 16 Posted 2007-06-28 23:56 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Originally posted by byxyk at 2007-6-28 21:15:
The parameter %0 is not always the same.
1. Double-click execution in Explorer
2. Run with full path in CMD
3. Run in the current directory in CMD

What are the differences?
Floor 17 Posted 2007-09-03 09:43 ·  中国 广西 南宁 西乡塘区 电信
中级用户
★★
Credits 259
Posts 164
Joined 2006-09-21 23:39
19-year member
UID 63296
Status Offline
Exquisite, going to bookmark it ^_^ September 3, 2007 9:33:53 Monday
Floor 18 Posted 2007-09-28 13:53 ·  中国 福建 三明 电信
中级用户
★★
Credits 458
Posts 211
Joined 2006-07-26 19:42
19-year member
UID 59307
Status Offline
Good stuff, I've been looking for it for a long time. Just in time to use the "%~dp0" thing, it's really great. Thanks to "redtek".
Floor 19 Posted 2007-09-28 16:09 ·  中国 四川 南充 营山县 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Originally posted by graper at 2007-6-28 18:58:


The above one can work when run directly in BAT mode, but it doesn't work when compiled into an EXE file with a tool; the path will become the path of the system temporary directory :(

Moreover, if I only want to get the upper level of the current file ...

Generally speaking, when an EXE file is compiled with a tool and then run, the EXE file will automatically decrypt the BAT file, and the decrypted BAT file will be placed in the system temporary directory, so the path will become the path of the system temporary directory
Floor 20 Posted 2008-03-13 00:58 ·  德国 法兰克福大学
初级用户
Credits 34
Posts 14
Joined 2008-03-12 19:28
18-year member
UID 112774
Gender Male
Status Offline
Floor 21 Posted 2008-04-08 18:12 ·  中国 北京 光环新网
初级用户
Credits 50
Posts 19
Joined 2008-03-31 15:10
18-year member
UID 114544
Gender Male
Status Offline
Great expert! Worth learning, thanks for sharing!!
Forum Jump: