|
llztt1
中级用户
  
积分 214
发帖 94
注册 2007-1-11
状态 离线
|
『楼 主』:
如何在批处理中获得本批处理文件的所在路径哈??
使用 LLM 解释/回答一下
有些小软件需要在其本路径下运行方可顺利加载必要运行文件,譬如W老大修改过的那个IFSDRV,加载中文936.CPI...
所以我想设置好了PATH路径后,在其他盘符下运行调用IFSDRV的批处理时,需要获得该批处理文件的路径(本批处理文件和IFSDRV同目录),然后来个GO.EXE那个路径,再运行,但怎么获得这个路径呢呢??
不想用绝对的路径,可否有什么系统命令直接取得这个路径??
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??
|
|
2007-2-4 07:55 |
|
|
Michael
钻石会员
       
积分 10046
发帖 3039
注册 2002-11-11
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
%0的百分号和0之间加点什么。
What to add between the percent sign %0 and 0.
|

简单就是美 |
|
2007-2-4 22:15 |
|
|
llztt1
中级用户
  
积分 214
发帖 94
注册 2007-1-11
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
呵呵,加点什么啊??
我想实现的东西就象这个例子:
设置好PATH各个路径,而这个批处理可能存在于其中任何一个路径中,如何在任意盘符下运行这个批处理自动转到这个批处理所在路径下???
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???
|
|
2007-2-5 11:06 |
|
|
Michael
钻石会员
       
积分 10046
发帖 3039
注册 2002-11-11
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
到批处理区去问吧,那里的人们整天摆弄这个东西。或者像我一样,不懂了就看命令的帮助。刚才查了一下,是%~p0,在cmd里输入for /?,解释的很详细。
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.
|

简单就是美 |
|
2007-2-5 11:36 |
|
|
llztt1
中级用户
  
积分 214
发帖 94
注册 2007-1-11
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
呵呵,发错地方了啊,我去批处理区问问
不过%~p0是在WINDOWS下CMD里的,在DOS中无法使用的。。有些遗憾啊。。
谢谢楼上
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
|
|
2007-2-5 12:32 |
|
|
Michael
钻石会员
       
积分 10046
发帖 3039
注册 2002-11-11
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
Originally posted by llztt1 at 2007-2-4 11:32 PM:
呵呵,发错地方了啊,我去批处理区问问
不过%~p0是在WINDOWS下CMD里的,在DOS中无法使用的。。有些遗憾啊。。
谢谢楼上
DOS下的啊,那还是别去了。
Originally posted by llztt1 at 2007-2-4 11:32 PM:
Hehe, posted in the wrong place. I'll go ask in the batch processing section.
But %~p0 is in CMD under WINDOWS, not available in DOS. It's a bit of a pity..
Thanks to the above
For DOS, then it's better not to go.
|

简单就是美 |
|
2007-2-6 00:06 |
|
|
zjghjs
初级用户
 
积分 46
发帖 19
注册 2007-2-7
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
来了两天,看得还是一头雾水:(
Been here for two days, still completely confused :(
|
|
2007-2-14 00:46 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
|
2007-2-14 06:28 |
|
|
llztt1
中级用户
  
积分 214
发帖 94
注册 2007-1-11
状态 离线
|
|
2007-2-15 00:32 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
那dir下自己
在返回信息里应该可以获得目录吧?
Then in the dir, by yourself. Should you be able to get the directory in the returned information?
|
|
2007-2-15 03:44 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
|
2007-2-16 13:03 |
|
|
freetree
初级用户
 
积分 31
发帖 9
注册 2007-1-18
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
如果TRUENAME和批处理文件在同一路径下,可用TRUENAME返回所在路径。
If TRUENAME and the batch file are in the same path, you can use TRUENAME to return the path where it is located.
|
|
2007-2-23 09:55 |
|
|
htysm
高级用户
   
积分 866
发帖 415
注册 2005-12-4
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
要是在纯DOS下真的好象没办法。在CMD下方法有的是。
If it's really in pure DOS, it seems there's no way. In CMD, there are plenty of methods.
|
|
2007-2-25 22:57 |
|
|
0451lym
高级用户
   
积分 760
发帖 357
注册 2005-10-10
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
APPEND
--------------------------------------------------------------------------------
使程序能打开所指定目录中的数据文件,就象该文件是在当前目录中一样。运行Windows时不要用这个命令。
所指定的目录称为添接目录。因为,对打开数据文件而言,对这些文件的查找,就好象它们已添接在当前目录中了。
语法 :
APPEND path] ]
要显示添接目录清单,可用:
APPEND
要删除现有的添接目录的列表,可用:
APPEND ;
参数 :
path
指定要添接到当前目录中去的目录及其所在驱动器(如果不同于当前驱动器)。可指定多个path,各项之间用分号(;)隔开。
;
当直接使用此符号时表示,删除现有的添接目录表。
开关项 :
/X
指出程序执行时,MS-DOS对添接目录是(/X:ON)否(/X:OFF)进行搜索。 /X:ON可略写为/X。如果要指定X:ON,必须在启动系统后,第一次用APPEND时进行指定。之后,X:ON和X:OFF可来回切换,默认值为/X:OFF。
/PATH:ON|/PATH:OFF
指出当路径中已包含程序正在寻找的文件名时,程序是否还要到添接目录中搜索该数据文件。默认设置为/PATH:ON。
/E
将添接目录表赋给名为APPEND的环境变量。本开关项仅能在启动系统后,第一次引用APPEND时使用。用了/E,就可用SET命令来显示添接目录表了。有关环境变量的说明,见<SET>命令。
注意:Microsoft Windows或Windows Setup程序,不能使用Append命令。
相关命令
关于设置可执行文件的搜寻路径,请参见<PATH>命令。
--------------------------------------------------------------------------------
APPEND─注解
运行APPEND与Microsoft Windows
APPEND不能与Microsoft Windows或Windows Setup程序一起使用。
多次运行APPEND
启动系统后,可随意多次使用APPEND。但要注意下列事项:
★ /E开关项在系统启动后,仅在APPEND第一次使用中有效。
★ 第二次及以后每次运行APPEND,必须略去.EXE文件扩展名。若试图输入APPEND.EXE 来运行APPEND,则APPEND只能加载一次。
将添接目录表存入环境中
在APPEND中可利用/E,将添接的目录列表赋给名为APPEND的环境变量。方法是,先执行仅带/E开关的APPEND命令,然后再执行一次APPEND,这次要把想添接的目录包括在内。在同一命令行中不能同时指定/E和path。
指定多个添接目录
添接多个目录时,目录项之间用分号(;)隔开。如果再次执行带path参数 的APPEND,则本次所指定的目录会取代前一个APPEND命令中指定的任何目录。
添接目录与DIR命令
执行DIR命令时,其执行结果的列表中不会包括添接目录中的文件名。
文件名冲突
如果添接目录中有文件和当前目录中文件同名,则打开当前目录的这个文件。
APPEND与创建新文件的程序一起使用
程序打开一个添接目录中的文件时,就象打开当前目录中的文件一样。如果该程序接着又将这个文件存放在一个新创建的同名文件中,则这个新文件创建在当前目录中(而不是添接目录中)。APPEND更适合用于不作修改的或虽修改但不作新文件备份的数据文件。 数据库程序 通常对数据文件进行修改但不作新备份。文本编辑器和文字处理器则通常借助于备份来存放修改过的数据文件。为避免混乱,不要与这些程序一起使用APPEND。
/X:ON开关与PATH命令的使用
一旦指定/X:ON,只需在命令提示符中输入程序名就能运行某个存放在添接目录中的程序。 平时我们常用PATH命令来指定该程序所在的目录。而如果您的程序在添接目录中,就不再需用PATH命令指出它的目录。 MS-DOS按以下顺序找到一个添接目录中的程序,即,首先是当前目录,再是添接目录,然后才是搜索路径PATH。
总是用到添接目录的MS-DOS函数
即使没有指定/X:ON,当程序调用下列MS-DOS中断21的函数时,仍利用了添接目录。
★ 打开文件(0Fh)
★ 打开文件句柄 (3Dh)
★ 读取文件大小 (23h)
当指定了/X:ON时,程序每次对上述及下列中断21h函数进行调用时,都用到了添接目录。
★ 查找第一项 (11h)
★ 查找第一个文件 (4Eh)
★ 执行程序(EXEC) (4Bh)
在网络驱动器中使用APPEND
APPEND命令也适用于网络驱动器上的目录添接。
--------------------------------------------------------------------------------
APPEND─例子
为了让程序打开B盘LETTERS目录下的数据文件和A盘ROORTS目录下的数据文件,就象它们是在当前目录中,可输入下列命令:
append b:\letters;a:\reports
添接同样的目录,并在MS-DOS环境变量中存放添接的目录表,可键入下列命令:
append /e
append b:\letters;a:\reports
上述命令都必须在启动系统后,首次执行APPEND命令时使用。
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.
|
|
2007-2-26 02:44 |
|
|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
都想复杂了!
其实直接在开头的时候
加一句
set programme_path=%cd%
后面直接调用 %programme_path%就好了
昨天也是刚碰到这样一个问题;
后来发现其实可以如此简单
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
|
|
2007-3-17 00:09 |
|