0

imagine I have a files with certain extensions (for example '.abc'). The default program I set for files with this special extension is a batch script with powershell commands in it, so when I doubleclick the file, it runs the script. It works.

Now my question is, can I somehow get the file path of the .'abc' file I opened? Is there a command for this?

Thank you.

Mofi
  • 46,139
  • 17
  • 80
  • 143
deedea96
  • 13
  • 1

1 Answers1

0

Inside of your batch file it should be possible to access the ".abc" file via parameter %1. Per default Windows sends the filename of the file you doubleclick to the receiving program (or batch script) as parameter one.

Try this inside of your batch file (near the top) and pick what suits your needs:

echo param1: %1
echo param1 unquoted: %~1
echo drive: %~d1  
echo drive and path: %~dp1  
echo filename and extension only: %~nx1
set myparam=%~1
echo myParam: %myparam%

See the help documentation of for for the "%~..." syntax by executing for /? in a cmd.exe command window. (Or read here: What does %~dp0 mean, and how does it work?)

user229044
  • 232,980
  • 40
  • 330
  • 338
Antares
  • 605
  • 3
  • 14
  • actually used this in the end: "set path=%~dp1%~nx1" thx for help! – deedea96 Apr 26 '20 at 19:06
  • Thanks for the update! :) You can rewrite this as `%~dpnx1` if you like. But this should actually be equivalent to just use `%~1`. But if it works, it works! :D – Antares Apr 26 '20 at 20:44
  • Are you aware, that you override (hide) the system environment variable PATH when you do a `set path=...`? The PATH entries consists just of the directory+path part, not including the filename+extension usually. – Antares Apr 26 '20 at 20:52
  • I use a different variable, i posted this just for describing purposes. – deedea96 Apr 27 '20 at 21:07