Program Executable Location

Klaus Major klausimausi at mac.com
Thu Feb 6 07:27:01 EST 2003


Hi Jez,

> Can I access the location of the executable being run ? For example, 
> if I
> create the standalone "C:\Program Files\MyApp\Myexe.exe" I want to
> programmatically get the directory "C:\Program Files\MyApp" so that I 
> can
> store some files underneath this. Also when running in browse mode I 
> would
> like the same code to give me the location of the revolution 
> executable.
>
> I am aware that I can examine defaultFolder on startup (which does 
> indeed
> give you the executable location) and store this in a global variable, 
> but
> this does not work well when testing the app in browse mode, since if 
> it
> executes the same code again by that time the defaultFolder will 
> probably
> point to somewhere else. A more secure way of getting the executable
> location would be preferable.

you can use a li'l function like this:

function where_am_i
    get the effective filename of this stack
    ### will deliver the complete path...

    set the itemdel to "/"
    delete item -1 of it
    ### strip the name of the standalone/stack

    return it & "/"
    ## ready for use :-)
    ## since in earlier days i used to forget the last "/"
    ## i got used to append it immediately ;-)
end where_am_i

Is fast, elegant and free ;-)

And will of course not touch the working directory/default folder.

Hope that helps.


Regards

Klaus Major
klausimausi at mac.com




More information about the use-livecode mailing list