I have an old 386 computer (without windows) which has MSDOS 6.22. So I cannot use any solution that built on cmd.exe (part of windows)
I want to pass current bat script path and name to another program within this bat code.
I try to use %CD%
but it looks like works only with cmd.exe
I try to use %0
argument, but it hold only the name of bat instead of name with full path
@echo off
set myPath=%cd%
myprogram.exe %myPath%\%0
It doesn't work. The passed parameter is \mybat.bat
when I started the bat program from it's directory with full name.
After the variables resolved, I want to something like this:
@echo off
myprogram C:\BATCH\MYBAT.BAT
Where the bat placed in c:\batch
directory, and it name is mybat.bat
How can I do this?
The solution of @Stephan is good, but requires a predefined helper file.
But you can also build a solution which doesn't need any predefined files.
@echo off
>temp1.bat echo @PROMPT SET _CD=$P
>temp2.bat command /c temp1.bat
call temp2.bat
del temp1.bat
del temp2.bat
echo currentDir=%_CD%
This can be used to get the current directory $P
, time $T
or date $D
, as these values are supported by the PROMPT command.