Board logo

标题: P运行的一个问题 [打印本页]

作者: 23112656     时间: 2008-9-6 02:49    标题: P运行的一个问题
代码如下: @echo off set ur=%0 for /f %%i in ('type "%ur:~0,-9%\url.txt"') do set n=%%i echo %n% pause <-------------这里加上暂停 问题就出在暂停这了,为什么我在cmd里执行这个P处理没问题,并能显示url里的内容.且还会提示暂停. 而当我双击直接运行这个P的时候就一闪而过了?我加了pause怎么还能一闪就关闭了呢?代码我检查了好遍应该是没问题的啊.难道是%0在作怪? [ Last edited by 23112656 on 2008-9-6 at 02:51 AM ]

作者: HAT     时间: 2008-9-6 10:42
%0代表的是批处理文件本身,而不是批处理所在目录 "%ur:~0,-9%\url.txt"这个路径肯定是不存在的

作者: 23112656     时间: 2008-9-6 17:25
可以我在cmd里执行这个P处理没问题,并能显示url里的内容呀.我刚把ur的值改为%cd%就不会双击后跳过了.但还是搞不懂%0应该可以打印出自身和自身包括的路径的啊,所以用:~0,-9去掉自身的名字只留下路径名+当前目录下的url.txt 可是还是一闪而过了...

作者: HAT     时间: 2008-9-6 18:15
再仔细看看for的帮助
In addition, substitution of FOR variable references has been enhanced. You can now use the following optional syntax: %~I - expands %I removing any surrounding quotes (") %~fI - expands %I to a fully qualified path name %~dI - expands %I to a drive letter only %~pI - expands %I to a path only %~nI - expands %I to a file name only %~xI - expands %I to a file extension only %~sI - expanded path contains short names only %~aI - expands %I to file attributes of file %~tI - expands %I to date/time of file %~zI - expands %I to size of file %~$PATH:I - searches the directories listed in the PATH environment variable and expands %I to the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found by the search, then this modifier expands to the empty string The modifiers can be combined to get compound results: %~dpI - expands %I to a drive letter and path only %~nxI - expands %I to a file name and extension only %~fsI - expands %I to a full path name with short names only %~dp$PATH:I - searches the directories listed in the PATH environment variable for %I and expands to the drive letter and path of the first one found. %~ftzaI - expands %I to a DIR like output line In the above examples %I and PATH can be replaced by other valid values. The %~ syntax is terminated by a valid FOR variable name. Picking upper case variable names like %I makes it more readable and avoids confusion with the modifiers, which are not case sensitive.