How to get selected Open With file & path sent to program

Just starting out? Need help? Post your questions and find answers here.
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

How to get selected Open With file & path sent to program

Post by yrreti »

For Example:
When I use Windows Explorer to select an rtf file, it automatically opens that selected file in the default rtf running program.
When I use Windows Explorer to select an rtf file, and select Open With, it lets me select an alternate program to open that rtf file, and then opens it in that program.

What I wanted to be able to do, like it is processed above. Is to use Windows Explorer to select a file, and then use 'Open With' to send that selected file to be processed by my PB program. I can easily create the "Open With" part via registry, or by selecting that program through the open With Selection, and both run my PB program fine.
But the selected file name is not transfered to my program to be processed, like it is with the previous examples.
It just runs my program.
How would I be able to get the selected file name and path to be sent to my PB program to be processed?
I appreciate any help and ideas on how to do this.
Thanks
platy
New User
New User
Posts: 6
Joined: Wed Jun 16, 2021 7:05 pm

Re: How to get selected Open With file & path sent to program

Post by platy »

Allen
Enthusiast
Enthusiast
Posts: 103
Joined: Wed Nov 10, 2021 2:05 am

Re: How to get selected Open With file & path sent to program

Post by Allen »

Hi,

You may try to use ProgramParameter() in your PB program to get the full file name.

Allen
Olli
Addict
Addict
Posts: 1242
Joined: Wed May 27, 2020 12:26 pm

Re: How to get selected Open With file & path sent to program

Post by Olli »

I think also

Code: Select all

Define argument.s

Repeat
 argument = ProgramParameter()
 Debug argument
Until argument = ""
(to test on the pb IDE : Compiler menu -> Compiler options -> Compile/Execute -> Executable parameter -> type the test arguments string)

It might be ok on all OSs...
User avatar
kenmo
Addict
Addict
Posts: 2047
Joined: Tue Dec 23, 2003 3:54 am

Re: How to get selected Open With file & path sent to program

Post by kenmo »

Hi,

On Windows you definitely want to check ProgramParameter(0) to get the path sent to program.

If you need to support multiple paths sent at the same time, use CountProgramParameters() and check from from index 0 to index (Count-1).

If you ever want to do this on Mac, it's more complicated, you need to use PB_Gadget_SetOpenFinderFiles(), see here:
viewtopic.php?f=19&t=50795&start=15#p391349
Jeromyal
Enthusiast
Enthusiast
Posts: 216
Joined: Wed Jul 17, 2013 8:49 am

Re: How to get selected Open With file & path sent to program

Post by Jeromyal »

Rebuild quoted parameters passed from explorer.

Code: Select all

Define Count
For Count = 0 To CountProgramParameters() - 1
  If FindString(ProgramParameter(Count), space(1))
    Args + chr(34) + ProgramParameter(Count) + chr(34) + space(1)
  Else
    Args + ProgramParameter(Count) + space(1)
  EndIf
Next
User avatar
mk-soft
Always Here
Always Here
Posts: 6252
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How to get selected Open With file & path sent to program

Post by mk-soft »

Code: Select all

If Chr(34) = #DQUOTE$
  Debug "Thats right!"
EndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: How to get selected Open With file & path sent to program

Post by yrreti »

I really appreciated all the good suggestions and help and interesting ways to approach this.

Because in my case, I just needed to get the first combined parameter of the file path and file name.
I just used the following:
; FirstParm$ = Running data that was passed to my running program
;eg: "D:\MyPB_pgms\___PageSelPgm\Page list.cfg" I selected Page list.cfg and used Windows Explorer Open With my program.
FirstParm$ = ProgramParameter(0) ;first parameter position is at 0
;Note: you can't pass any spaces in params.
;So you have to replace all spaces with another character to pass. (such as spaces in paths and file names)
;I used the ~ character), and then replaced back to a space after you receive it.
;Using the following works fine every time.
FirstParm$=ReplaceString(FirstParm$,"~"," ",1)

;to test to see if it worked.
;FirstParm$ ="D:\MyPB_pgms\___PageSelPgm\Page list.cfg"
If Trim(FirstParm$)<>""
MessageRequester("*--------------------- got start parm ----------------------- *",FirstParm$,#PB_MessageRequester_Ok)
EndIf
Thanks very much for all your help.

Yrreti
BarryG
Addict
Addict
Posts: 4178
Joined: Thu Apr 18, 2019 8:17 am

Re: How to get selected Open With file & path sent to program

Post by BarryG »

yrreti wrote: Fri Sep 16, 2022 11:33 pmWhat I wanted to be able to do, like it is processed above. Is to use Windows Explorer to select a file, and then use 'Open With' to send that selected file to be processed by my PB program
When I read that, I assume you want to trigger and display the actual Explorer "Open With" dialog?
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: How to get selected Open With file & path sent to program

Post by yrreti »

First of all, I want to apologize. When I wrote that last part late yesterday, I guess I was half asleep after a long day.
I woke up at 3 am this morning, and suddenly realized what I had entered and wanted to correct that entry because it didn't
make sense. I copied code in there that wasn't suppose to be there.
I found that code from another program I wrote long ago, where I needed to
send a phrase which contained spaces

to another program that I wrote to act upon. I had replaced the spaces in that phrase with the ~ character so it would work without
having to retrieve and add the sections together again, and replaced the ~ character back to spaces after it received the phrase.
But then I realized that when selecting a file
and using Windows Explorer Open With

My program and FirstParm$ = ProgramParameter(0),
for some reason I realized that I don't have to worry about the spaces, as it works even with spaces in the path name and the file name.
Explorer's Open With must take care of that issue.
I just used the MessageRequester code part just to see and verify the end result of ProgramParameter(0), before adding that code
with out the MessageRequester part back into my program.
At any rate, it seems to work for me every time, but I appreciate all the good info added regarding how to possibly do this.
This forum is a great forum, and has always been so helpful.
Thanks for all your help.

yrreti
Post Reply