Greg Matheson <lang@...> writes:
> C:\s\etc>if EXIST %0\..\bin\sh.exe echo 1
Is this from a batch file? Outside a batch file, "%0" isn't valid, so
"%0" is used literally without substitution.
> So, %0\.. equals .\ ?
It means "pretend you had a directory '%0' and than you go up one
level". It makes more sense in a batch files where "%0" is replaced
with the batch file name itself as called on the command line, so
"%0\.." can expand to "c:\some-directory\mybatch.bat\.." which is
interpreted as "c:\some-directory". The trick is that Windows doesn't
first checking that there is a directory
"c:\some-directory\mybatch.bat" before resolving the ".." part.
The snag is - I had forgot to mention it before, because I had
forgotten myself - you actually have to call that batch as
"c:\some-directory\mybatch param param". I.e. while "%~dp0" will
calculate the path of the batch file for you, even when
"c:\some-directory" is in your PATH and when you just say "mybatch
param param", OTOH the syntax "%0\.." doesn't do that, so for a call
through the PATH it will not work, because "mybatch\.." *is* indeed
actually just a complicated way of saying ".".
If I needed to, I was usually using aliases or simple wrapper batches
to circumvent that problem.