?
Solved

pure dos equivalent of NTs %~dp0..

Posted on 2003-02-21
3
Medium Priority
?
969 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:asjf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Expert Comment

by:pbarrette
ID: 7994393
Hi Asjf,

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
0
 
LVL 10

Accepted Solution

by:
pbarrette earned 200 total points
ID: 7994463
Oops,

Did I actually post "CMD /C" for a pure DOS answer? That should be "COMMAND /C" in both instances.

pb
0
 

Author Comment

by:asjf
ID: 8007463
thanks!
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question