![]() |
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-03 20:26 |
48,038 topics / 350,123 posts / today 0 new / 48,251 members |
| DOS批处理 & 脚本技术(批处理室) » How to get the path where the current batch file is located in batch processing? |
| Printable Version 2,713 / 17 |
| Floor1 llztt1 | Posted 2007-02-04 07:55 |
| 中级用户 Posts 94 Credits 214 | |
|
Some small software need to run in its own path to smoothly load necessary running files, for example, the IFSDRV modified by Boss W, which loads Chinese 936.CPI...
So I want to set the PATH path, and when running the batch file that calls IFSDRV in other drives, I need to get the path of this batch file (this batch file is in the same directory as IFSDRV), then get the path of GO.EXE, and then run it, but how to get this path?? I don't want to use absolute paths. Is there any system command to directly get this path?? |
|
| Floor2 Michael | Posted 2007-02-04 22:15 |
| 钻石会员 Posts 3,040 Credits 10,051 | |
|
What to add between the percent sign %0 and 0.
|
|
| Floor3 llztt1 | Posted 2007-02-05 11:06 |
| 中级用户 Posts 94 Credits 214 | |
|
Hehe, what to add??
The thing I want to implement is like this example: After setting the PATH paths, and this batch file may exist in any of these paths, how to run this batch file in any drive letter and automatically go to the path where this batch file is located??? |
|
| Floor4 Michael | Posted 2007-02-05 11:36 |
| 钻石会员 Posts 3,040 Credits 10,051 | |
|
Go to the batch processing area to ask, where people tinker with this all day long. Or like me, when I don't understand, I look at the help of the command. Just now I checked, it's %~p0, and entering for /? in cmd explains it in detail.
|
|
| Floor5 llztt1 | Posted 2007-02-05 12:32 |
| 中级用户 Posts 94 Credits 214 | |
|
Hehe, I posted in the wrong place. I'll go ask in the batch processing section. But %~p0 is in CMD under WINDOWS, and it can't be used in DOS. It's a bit of a pity.. Thanks to the person above
|
|
| Floor6 Michael | Posted 2007-02-06 00:06 |
| 钻石会员 Posts 3,040 Credits 10,051 | |
Originally posted by llztt1 at 2007-2-4 11:32 PM: For DOS, then it's better not to go. |
|
| Floor7 zjghjs | Posted 2007-02-14 00:46 |
| 初级用户 Posts 19 Credits 46 | |
|
Been here for two days, still completely confused :(
|
|
| Floor8 slore | Posted 2007-02-14 06:28 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
| Floor9 llztt1 | Posted 2007-02-15 00:32 |
| 中级用户 Posts 94 Credits 214 | |
| Floor10 slore | Posted 2007-02-15 03:44 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
Then in the dir, by yourself. Should you be able to get the directory in the returned information?
|
|
| Floor11 terse | Posted 2007-02-16 13:03 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
Try "pushd 路径"
|
|
| Floor12 freetree | Posted 2007-02-23 09:55 |
| 初级用户 Posts 9 Credits 31 | |
|
If TRUENAME and the batch file are in the same path, you can use TRUENAME to return the path where it is located.
|
|
| Floor13 htysm | Posted 2007-02-25 22:57 |
| 高级用户 Posts 415 Credits 866 | |
|
If it's really in pure DOS, it seems there's no way. In CMD, there are plenty of methods.
|
|
| Floor14 0451lym | Posted 2007-02-26 02:44 |
| 高级用户 Posts 357 Credits 760 | |
|
APPEND
-------------------------------------------------------------------------------- Enables a program to open a data file in a specified directory as if the file were in the current directory. Do not use this command when running Windows. The specified directory is called the append directory. For opening data files, searches for these files act as if they were appended to the current directory. Syntax: APPEND path] ] To display the list of append directories, use: APPEND To delete the existing list of append directories, use: APPEND ; Parameters: path Specifies the directory and its drive (if different from the current drive) to append to the current directory. Multiple path can be specified, separated by semicolons (;). ; When used directly, this symbol deletes the existing list of append directories. Switches: /X Indicates whether MS-DOS searches the append directory when the program executes (/X:ON) or not (/X:OFF). /X:ON can be abbreviated as /X. If /X:ON is specified, it must be done when APPEND is first used after the system is booted. After that, /X:ON and /X:OFF can be switched back and forth, with the default being /X:OFF. /PATH:ON|/PATH:OFF Indicates whether the program searches the append directory for the data file even if the file name is already in the path the program is looking for. The default setting is /PATH:ON. /E Assigns the append directory list to an environment variable named APPEND. This switch can only be used when APPEND is first referenced after the system is booted. With /E, you can use the SET command to display the append directory list. For instructions on environment variables, see the <SET> command. Note: The Append command cannot be used with Microsoft Windows or the Windows Setup program. Related Commands For setting the search path for executable files, see the <PATH> command. -------------------------------------------------------------------------------- APPEND─Notes APPEND and Microsoft Windows APPEND cannot be used with Microsoft Windows or the Windows Setup program. Running APPEND Multiple Times You can use APPEND multiple times after the system is booted. But note the following: ★ The /E switch is only effective in the first use of APPEND after the system is booted. ★ The .EXE file extension must be omitted when APPEND is run the second time and later. If you try to enter APPEND.EXE to run APPEND, APPEND will only be loaded once. Storing the Append Directory List in the Environment You can use /E in APPEND to assign the list of appended directories to an environment variable named APPEND. The method is to first execute the APPEND command with only the /E switch, and then execute APPEND again, including the directories you want to append. You cannot specify /E and path in the same command line. Specifying Multiple Append Directories When appending multiple directories, separate the directory entries with semicolons (;). If you execute APPEND with the path parameter again, the directories specified this time will replace any directories specified in the previous APPEND command. Append Directories and the DIR Command The DIR command's execution result list does not include file names from the append directories. File Name Conflicts If there is a file with the same name in the append directory and the current directory, the file in the current directory is opened. APPEND and Programs That Create New Files When a program opens a file in an append directory, it is as if it were opening a file in the current directory. If the program then saves this file as a new file with the same name, the new file is created in the current directory (not the append directory). APPEND is more suitable for data files that are not modified or are modified but not backed up as new files. Database programs usually modify data files but do not back them up as new files. Text editors and word processors usually store modified data files with backups. To avoid confusion, do not use APPEND with these programs. /X:ON Switch and PATH Command Usage Once /X:ON is specified, you can run a program stored in an append directory by simply entering the program name at the command prompt. Normally, the PATH command is used to specify the directory where the program is located. But if your program is in an append directory, you no longer need to use the PATH command to indicate its directory. MS-DOS finds a program in an append directory in the following order: first the current directory, then the append directory, and then the search path PATH. MS-DOS Functions That Always Use the Append Directory Even if /X:ON is not specified, when a program calls the following interrupt 21h functions of MS-DOS, the append directory is still used. ★ Open file (0Fh) ★ Open file handle (3Dh) ★ Read file size (23h) When /X:ON is specified, the program uses the append directory each time it calls the following interrupt 21h functions. ★ Find first entry (11h) ★ Find first file (4Eh) ★ Execute program (EXEC) (4Bh) Using APPEND on Network Drives The APPEND command is also applicable to appending directories on network drives. -------------------------------------------------------------------------------- APPEND─Examples To enable a program to open data files in the LETTERS directory on drive B and the REPORTS directory on drive A as if they were in the current directory, enter the following command: append b:\letters;a:\reports To append the same directories and store the list of appended directories in the MS-DOS environment variable, type the following commands: append /e append b:\letters;a:\reports These commands must be used when APPEND is first executed after the system is booted. |
|
| Floor15 bjsh | Posted 2007-03-17 00:09 |
| 银牌会员 Posts 621 Credits 2,000 | |
|
It's all overcomplicated!
Actually, just add a line at the beginning set programme_path=%cd% Then directly call %programme_path% later. I just encountered such a problem yesterday; Later I found out it can be so simple |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |