Pass list of files to another program

Opus 9 users: Ignore this post and see the reply below instead. The method in this post was for Opus 8 and there is now a much better way to achieve this in Opus 9.

Some command-line programs let you give them a file with a list of filenames to work on. This can be useful when you want to pass so many filenames that listing them on the command-line directly would make the line longer than Windows allows.

You can do this with an "MS-DOS Batch Function" type button like this:

if exist "%TEMP%\opus_file_list.txt" ( del "%TEMP%\opus_file_list.txt" ) echo {filepath$}>>"%TEMP%\opus_file_list.txt" echo FILE LIST: type "%TEMP%\opus_file_list.txt" pause
Replace the "type" command with the one you want to run on the file list. Remove the "echo FILE LIST:" line as well; it's just there to prove that the list of filenames comes from the type command and not the lines before it.

Of course, don't run the button twice at once as they'll both use the same temp file.

Note that the above is unnecessary in Directory Opus 9 (and above) as you can use {file|filem}, {allfilepath|filem}, etc. to automatically generate temporary files listing the selected items and feed the temp-file name to the program you are running.

For example, this will print the list of all selected files (full paths), just like the example above does:

type {allfilepath|filem} pause

(Of course, there are easier ways to print the selected file names. This is just meant to demonstrate how the {...|filem} feature works.)

Hi nudel,

I must be misunderstanding this. I'm trying to test this by passing the filenames of the selected files in the current lister to a Python script.

My button is currently set up with:

<?xml version="1.0"?> <button backcol="none" display="both" textcol="none"> <label>New Button</label> <icon1>#newcommand</icon1> <function type="batch"> <instruction>k:\Documents\Programming\Scripts\python\farg.py {allfilepath|filem}</instruction> <instruction>pause</instruction> </function> </button>

The script itself should take the filenames passed on the command line and print them out in a dos window, confirming that they were passed as expected.

However, what happens is that a dos window opens, but it contains:

[quote]C:\DOCUM~1\pt\LOCALS~1\Temp\dop7C1.tmp
Press any key to continue . . .
[/quote]

Any thoughts as to what I might be doing wrong?

Many thanks,

pt

The |filem is telling Opus to write the selected filenames to a temporary file, and then pass the name of that temporary file to your script.

Thanks jon! Works perfectly now.

All the best,

pt

What if you want to do a similar thing for a non-command line program? For example, what if I want to click on a selection of mp3 files and then click a button which will open my chosen mp3 player and pass the selection of files to it? Is this possible?

Brian

If your chosen mp3 player supports that then yes.

Below is a rough example of one way to do it. Of course you would need to substitute the full path to your desired mp3 player. The {f} control code represents the files you have selected in Opus.

"C:\Program Files\My mp3 player\play.exe" {f}

Thanks for the reply. That worked, but only the first selected file was passed to the program. It took me a while to work out where you got that argument from because it wasn't in my list, then I realised you need to tick the box which says "show short arguments". From that, I found that a lowercase {f} passed a file, and an upper case {F} passes all files. I selected the latter, and it worked!

I'm not fully understanding the use of the commands and arguments though. Going to have to invest some time into the manual I think, because now I want a button that adds to the playlist as well!!! I'd like to add hot keys to them so I can select MP3 files and then press a hot key to start the program and pass the files to it, or a different hotkey to add to the playlist. You can do all of this already by right-clicking the files and selecting the relevant menu option, but scanning through the menu gets on my nerves so it'd be better if I can get Dopus to do it for me instead.

Thanks for your help.

Brian

Gentle reminder: Please ask questions in Help & Support.