Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch: How to read a path from a double-clicked file?

I am thinking about associating a file type extension to a batch script (.foo), so when double-clicking a file with .foo extension, this script will execute. The point is I do not know if there is a way to tell the script the path of the "executed" file (ie, which variable, if any, holds the path of the double clicked file).

Thank you.

like image 930
Mr. Istery Avatar asked Jan 20 '26 12:01

Mr. Istery


1 Answers

The executed file is passed as first argument to the script. A simple example will show. Create a batchfile (for example foo_command.cmd) which contains:

echo %* > %~dpn0.log

Execute your desired filetype and connect it to the batchfile. This will write a file named foo_command.log (in the directory of foo_command.cmd) which contains all arguments passed to the script. You will see, it is the full path of the executed File.

In general the variable %1 in the script holds the path and there are no other variables set by default.

like image 115
RoKi0815 Avatar answered Jan 23 '26 21:01

RoKi0815



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!