What does "%1" mean in File types Action/Context menus when

After some deliberation I decided this should be a new post

Searched for

  • %1
  • command line switches

Relevant Posts

In the context of these posts:

I see things like
...uedit32.exe "%1"
or
...uedit32.exe {filepathshort}
or
....uedit32.exe %~s1
or
...uedit.exe %~fs1

etc.
They are discussing switches I think in the context of places like this:
(Broken imageshack link removed.)

Here is what I have gleaned:

  • These are variables (windows?) used to represent values to be passed to the application in question
  • There is something in common with Windows Explorer here
  • There is reference to HKEY_CLASSES_ROOT\SystemFileAssociations.

Is there a set of definitions or references anywhere?

All this is against a background where I am running an AutoIT script successfully from a lister but when I try and run it from a hotkey program I use (KeyText. Similar I think to AutoHotkey and others) then it does the wrong thing...

%1 is the code which Explorer uses to insert the path to a file into a command line. Opus can use it as well.

%~fs1 is a variation which inserts the short version of the path.

There's a document somewhere on Microsoft's site with all the variations but it's virtually impossible to find as search engines are useless at things like "%1" which they turn into "1" :frowning:

If you're creating buttons that are only run within Opus then you don't have to use the cryptic %1 stuff and can use things like {filepath} instead.

If you go to a CMD prompt and type

for /?

And then press ENTER you can find some descriptions for arguments like %1. You'll have to drill quite aways down in that help text but in that help description you should find references to variables such as %I and it follows the same syntax as %1. In a nutshell here's some descriptions on how %1 (or %2 or %3 etc) can be parsed:

[code]%~1 - expands %1 removing any surrounding quotes (")
%~f1 - expands %1 to a fully qualified path name
%~d1 - expands %1 to a drive letter only
%~p1 - expands %1 to a path only
%~n1 - expands %1 to a file name only
%~x1 - expands %1 to a file extension only
%~s1 - expanded path contains short names only
%~a1 - expands %1 to file attributes of file
%~t1 - expands %1 to date/time of file
%~z1 - expands %1 to size of file

The modifiers can be combined to get compound results:
%~dp1 - expands %1 to a drive letter and path only
%~nx1 - expands %1 to a file name and extension only
%~fs1 - expands %1 to a full path name with short names only
%~dp$PATH:1 - searches the directories listed in the PATH environment variable for %1 and expands to the drive letter and path of the first one found.
%~ftza1 - expands %1 to a DIR like output line[/code]

I don't think Explorer supports any of those codes, and I know Opus certainly doesn't. They're specific to the command prompt.

I checked and things like %~s1 and %~fs1 definitely do not work in the registry/Explorer for file types. Those things only work in MS-DOS batch files (and Opus batch-mode buttons, which are turned into MS-DOS batch files).

Registry/Explorer/file type command-lines are limited to using %1 and %L as far as I know. (There might be a few others.)

You're right, Explorer and most programs won't recognize those codes, I should have clarified that when I posted my little chart. :blush:

For the most part it's batch files and certain specialized programs (usually command processor related) that will recognize the different variations.

Wasn't just you. I did it as well, quoting from the thread which I think spawned this one, without realising those things are DOS-only. :slight_smile:

Not for the first time I have found it better and easier to work within Opus. Here is my fix for anyone who might find this useful. This in fact automates the process described here for those who are interested. This is about creating shortcuts within Opus which my be advantageous because you can create relative shortcuts. The process of creating a shortcut within Opus is described here:
[url]Shortcuts with relative reference]
And there are more details that may be of interest here:
[url]DCF Shortcut Behaviour]

Now with the help from this post I have created a menu item to call an AutoIT script which does this for me all automatically. Happy days :slight_smile: