So basicly I want to make a batch file that can execute other files, while learing its own location on execution. It should then use it own path as a reference to the other files. How should I go about coding that or are there any guides for exactly that? Thanks in advance!
Asked
Active
Viewed 517 times
-1
-
1A batch file is referenced with `%0`. You most often would use modifiers with that too, _(take a look at the output from entering `call /?` at the Command Prompt, to see those modifiers, and replace the `1` with `0` as necessary)_. – Compo Dec 19 '19 at 23:07
-
1there are a lot of duplicates: [Get current batchfile directory](https://stackoverflow.com/q/17063947/995714), [How do I find the current directory of a batch file, and then use it for the path?](https://stackoverflow.com/q/16255184/995714), [How to get the path of the batch script in Windows?](https://stackoverflow.com/q/3827567/995714)... – phuclv Dec 20 '19 at 01:36
1 Answers
0
The batch file name as entered via command line is stored in %0. Using file expander to get other parts. You can put the following code into a batch file and try it out:
REM print batch filename as user entered
echo %0
REM print full file name: d - drive, p - path, f - filename
echo %~dpf0
REM print path only
echo %~dp0
The current directory is stored in %CD%, in case you need it.

Harvey Pham
- 623
- 4
- 17
-
1Your answer needs revising. Take a look at the output from entering `call /?` for assistance with it. – Compo Dec 20 '19 at 00:57