Launching files with unknown file extensions

If there a better way of achieving the below. Basically I always know the name of the ‘file’ minus it’s extension, but the extension will always be one of the three choices. The file is always stored in the same location, but under a year/month directory structure depending on when it was created. I always know where to find it to ‘launch’ it. The below works fine, it just seems long winded.

The files live on a server, so basically under windows command line dir server\location\year\month\filename.* would retrieve the whole filename but I don’t want to shell out twice if I can avoid - running batch file may be the answer. Open to views and suggestions.

settings(5) is the server UNC

[code]dim yr, mnth, dte, doc, fname as string
doc=lbDocuments.cell(lbdocuments.listindex,0)
yr=mid(lbDocuments.cell(lbdocuments.listindex,3),1,4)
mnth=mid(lbDocuments.cell(lbdocuments.listindex,3),6,2)
dte=mid(lbDocuments.cell(lbdocuments.listindex,3),9,2)
if right(settings(5),1)="" then
settings(5)=left(settings(5),len(settings(5))-1)
end if

fname=settings(5)+""+yr+""+mnth+""+doc

Dim f as FolderItem
dim i as Integer
dim ext(3) as String
ext(1)=".tif"
ext(2)=".doc"
ext(3)=".msg"

for i=1 to 3
f=GetFolderItem(fname+ext(i))
If f.exists then
fname=fname+ext(i)
Dim s As Shell
s=New Shell
#if TargetWin32
s.execute fname
#endif
exit For
end if[/code]
next

I’d say you can skip the shell to launch the file.
Just do

f.Launch

and it will open with the right program

Thank you.

Is there a way to choose the proper program for launch, other than the standard program in the OS?

I want to be able to choose one of several programs to open a file with during runtime.

Victor, that depends on the OS. On OSX, for instance, you’d launch the desired app with FolderItem.Launch, then use an AppleEvent to send it the file(s) to open. Or use one of the OS functions that you can find in macoslib.

On Windows and Linux, you’d rather start the app with the shell and pass the path(s) to the file(s) as arguments.

Using OSX.

With Launch the file opens with the standard program set in OSX. I want to open it in other suiting programs.

Problem not yet solved but I avoided it by opening the program via the shell, with the filename as parameter. But not the solution I hoped for.

Victor, if you do that, then use then “open” command. If you don’t yet, enter “open -h” to learn how to use it. Do not launch the executable inside /Contents/MacOS/ directly, or you’ll get odd side effects such as starting multiple copies of the same app, and other things.

Thanks for the tip. It’s working fine now with any program i prefer.