1.

Solve : batch help filename?

Answer»

How WOULD I find out the name of the batch file that's running the current command?

i.e. If I run abc.bat, what command would return the value of "abc.bat"?%1-9 are the parameters paseed to a batch file.

%0 is the batch file itself.
Quote from: justaguylooking on August 13, 2009, 09:29:37 AM

%1-9 are the parameters paseed to a batch file.

%0 is the batch file itself.


More exactly, it is the command line that called it.

If this is myname.bat:

Code: [Select]@echo off
echo %0

If you are in the same folder and you type myname.bat, you will see "myname.bat" echoed to the screen. If you type "myname" it will echo "myname". This behaviour also occurs if you save it to a folder on your PATH and call it by either of these two methods.

If you type the WHOLE path e.g. "C:\batch\myname.bat", then that is what %0 will be. If you open the folder in Windows Explorer, and double click on the batch file's ICON, %0 contains the full drive, path, name and extension, surrounded by quotes.

To avoid this ambiguity, you can get the name, extension, path and drive by using the %~d0, %~dp0, %~nx0 etc variable modifers DESCRIBED in the FOR documentation. For example the drive LETTER, path, name and extension is %~dpnx0



Discussion

No Comment Found