Re: program directory
- Posted by Nick <metcalfn at ALPHALINK.COM.AU> Apr 22, 1999
- 504 views
Thanks Ralf. I suspected there was something I had overlooked, and that was indeed it. --Nick Ralf Nieuwenhuijsen wrote: > > A question: > > I have been wondering for a while now, how does one find out the > > directory a program is in when it was run? Not the directory it was run > > from, given by current_dir() or the location of ex.exe given by > > examining the command_line() (the program is not bound), but the > > location of the .ex file itself. > > include misc.e > constant cl = command_line () > sequence s > s = reverse(cl[2]) > if find ('\\', s) then > s = s[find('\\',s)..length(s)] > end if > puts (1, "The directory of the .ex file or the .exe file (when bound) is: " & > reverse (s) & '\n') > > -- An explenation: > -- Command line always returns at least a 2-element-sequence. > -- { path_name_of_interpreter , path_name_of_code , ...} > > With bound files, where the path and filename of the interpreter is the same > as that of the code, the first two arguments are > the same. With unbound file they are not. Most likely it will be something > like .. > > { "c:\\euphoria\\bin\\ex.exe" , "c:\\projects\\progs\\frog.ex", ...} > > > for example.. > > I have a program, frog.ex in the directory c:\euphoria\progs\frog. It > > needs a data file in the same directory. > > Say a friend of mine gets the program, installs it in windows and > > double-clicks on the .ex icon. (he has .ex files calling ex.exe) My > > program will then look in c:\windows or some other strange place for > > it's data file, exiting ungracefully when it can't be found. > > This is what 'pifs' are really for. You can tell windows for an dos-executable > what the 'target'-directory must be. > This is the default directory that applies when opening files without any > path. > > > I am reluctant to specify an absolute path to the data file, after all > > programs that force install into a particular directory kind of suck, > > huh. I can't tell my friend to change his system configuration either, > > just to run my program? no way! > > > I hope I have overlooked the obvious. Most of us appear to be content > > with looking in the current directory, or relative to it for data and > > images, hoping the user hasn't typed something like > > c:\>ex c:\euphoria\progs\frog.ex > > as I suspect happens sometimes, well maybe not, but windows does this > > kind of thing and one can't guarantee it won't happen after all. > > Well, anyways, thankfully Euphoria _is_ quite capable of telling us the > source-directory. > Good luck with your program. > > Ralf