Windows batch file reference to own directory

Posted by rwallace on Super User See other posts from Super User or by rwallace
Published on 2011-02-15T22:39:53Z Indexed on 2011/02/15 23:28 UTC
Read the original article Hit count: 155

Filed under:
|
|

Suppose you have C:\foo\foo.bat which needs to refer to C:\foo\foo.txt. It may be run from a different directory, but needs to get foo.txt from its own directory, not the current directory. Obviously this could be done by putting the full path C:\foo\foo.txt in foo.bat.

The twist is, it's not known at the time of writing the batch file, where it will end up residing on the user's machine, so what the batch file actually needs to do is get foo.txt from the directory where I live, wherever that happens to be. (In a C program I'd use argv[0] but that doesn't seem to work with batch files.)

Is there a way to do this?

© Super User or respective owner

Related posts about Windows

Related posts about command-line