asjf
asked on
pure dos equivalent of NTs %~dp0..
hi,
I need to get the pathname of the current script running on all windows platforms.
On Win NT you can do
@echo hello from %~dp0
but I can't find an equivalent on windows9x. Getting the current path is sufficient either since you may be running the batch file from elsewhere..
any help would be soo appreicated,
thanks,
asjf
I need to get the pathname of the current script running on all windows platforms.
On Win NT you can do
@echo hello from %~dp0
but I can't find an equivalent on windows9x. Getting the current path is sufficient either since you may be running the batch file from elsewhere..
any help would be soo appreicated,
thanks,
asjf
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks!
This isn't the prettiest, but it will store the current path and the path to the batchfile into a variable:
:: -----PATHS.BAT------
@ECHO OFF
CD > C:\TEMP\CURPATH.TXT
CD %0\..
CD > C:\TEMP\BATPATH.TXT
ECHO @PROMPT SET CURPATH=>C:\TEMP\TEMP1.BAT
TYPE C:\TEMP\CURPATH.TXT >> C:\TEMP\TEMP1.BAT
ECHO @PROMPT $H >> C:\TEMP\TEMP1.BAT
CMD /C C:\TEMP\TEMP1.BAT >> C:\TEMP\TEMP2.BAT 2>NUL
CALL C:\TEMP\TEMP2.BAT 2>NUL
ECHO @PROMPT SET BATPATH=>C:\TEMP\TEMP1.BAT
TYPE C:\TEMP\BATPATH.TXT >> C:\TEMP\TEMP1.BAT
ECHO @PROMPT $H >> C:\TEMP\TEMP1.BAT
CMD /C C:\TEMP\TEMP1.BAT >> C:\TEMP\TEMP2.BAT 2>NUL
CALL C:\TEMP\TEMP2.BAT 2>NUL
CD %CURPATH%
DEL C:\TEMP\CURPATH.TXT
DEL C:\TEMP\BATPATH.TXT
DEL C:\TEMP\TEMP1.BAT
DEL C:\TEMP\TEMP2.BAT
ECHO BATPATH = %BATPATH%
ECHO CURPATH = %CURPATH%
:: -----PATHS.BAT------
This is about the only way to do this using pure DOS. It is also not perfect. If the batchfile is invoked from a directory other than the current directory without specifying the full path, then the BATPATH value will be reported as the current path.
This is because the %0 variable holds the text of the last command run. In the example above, the last command doesn't include the full path to the batchfile because it was invoked without specifying the full path at the command-line.
pb