Page 1 of 1
Passing selected files to their Default Program?
Posted: Sat Dec 06, 2025 2:58 am
by CodingBlind
As per subject, I would like to be able to select a group of files in my presently, very simple Explorer application and pass them for processing / playing, in their default application; In particular, mp3 files. Once submitted, I require no further interaction from the executing program.
Using RunProgram(MyFile$) one file can be played.
The obvious solution is to create a .m3u or .pls file. For non-music files, one might create a batchfile .bat.
Is there a better (more technical way of doing this? How would Windows do it?
Many Thanks in advance
Wayne
Re: Passing selected files to their Default Program?
Posted: Sat Dec 06, 2025 5:04 am
by BarryG
Does the default program take command-line parameters for the files being sent? If so, you can use RunProgram in a loop of all files to submit, with each file being RunProgram's parameters flag.
Something like this:
Code: Select all
Dim filelist$(3)
filelist$(1)="One.mp3"
filelist$(2)="Two.mp3"
filelist$(3)="Three.mp3"
tool$="c:\something.exe" ; App that does the processing.
tooldir$=GetPathPart(tool$)
For n=1 To 3 ; Send all files one-by-one to the processing tool.
RunProgram(tool$,filelist$(n),tooldir$,#PB_Program_Hide|#PB_Program_Wait)
Next
Debug "All files processed!"
Re: Passing selected files to their Default Program?
Posted: Sat Dec 06, 2025 12:39 pm
by Axolotl
If you don't want to specify the related app, you can use different ways to detect the associated file extention.
Keep in Mind, that windows is doing this by the file extensions.
Easy Test with the cli tool
All the stuff you need is in the registry (database)
Code: Select all
Procedure.s GetAssociatedProgram(Extension$)
; see also Link below
Datei verknüpfen
Another Idea: (probably wrong)
Code: Select all
Global File$ = ""
; instead of:
RunProgram(File$)
; use this
ShellExecute_(0, @"open", @File$, 0, 0, #SW_SHOW)
; because 2'nd Parameter "open" can be used for more precise tasks
Re: Passing selected files to their Default Program?
Posted: Sat Dec 06, 2025 1:22 pm
by CodingBlind
BarryG,
Thank you for your reply and code snippet.
As suggested by you, the command line provided a solution to this problem. My preferred player is the legacy version of Winamp; and it does play space-separated filenames.
My first reaction was that the command line would not provide enough space. That perception harks back to my foray into 8086 Assembly Language programming in the early '90s. The first instruction of a .com program begins at an offset of 100 Hex, with the FF bytes below that, available for the command line.
Fortunately, under Windows, the command line provides 8191 bytes. Even using UTF8 strings, that is 4094 characters.
Entering ProgName$ and FileNames$ strings as parameters in RunProgram() the compiler returned an 'Incorrect Number of parameters' error, until I added a Working Directory. From my reading of the Hellp topic, all parameters other than ProgName are optional?
Whilst it is unlikely I would be sharing my program, if I did, the problem would be knowing which player the user has on their system. The filetype information is stored in Registry and I'm not going there!
So, I favour the playlist approach.
While I have been composing this verbose message, another reply has arrived. So, I am keen to read another person's thoughts.
Wayne