Getting the "launch" dir

Feature requests for future versions of Hollywood can be voiced here
Post Reply
User avatar
jPV
Posts: 603
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Getting the "launch" dir

Post by jPV »

I have programs that take an input file as a command line argument, and if the file is given without a path (the input file is in the same dir with a Hollywood program, or you launch the Hollywood program from elsewhere like SYS:Applications/MyProgram filetobeopened.txt), Hollywood doesn't find the file because current directory is changed to the location of the Hollywood program. If the program also needs data files from its directory, disabling the automatic directory changing isn't a solution alone.

I didn't find any command from Hollywood to get the directory the program was initially launched, but is there anything for that?

I just made a work-around for it now like this:
1) Enable the NoChDir option
2) Store the current directory with the GetCurrentDirectory()
3) Use the GetProgramInfo() to get the program directory
4) Change the current directory manually to the program dir with the ChangeDirectory() function
5) Handle the file opening with the stored dir if the file doesn't contain a path

So, it would be much more convenient to have a function, or some other way, to get the directory the program was launched from.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Getting the "launch" dir

Post by airsoftsoftwair »

Hmm, sounds like a job for GetFileArgument()?
User avatar
jPV
Posts: 603
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Getting the "launch" dir

Post by jPV »

Maybe, if it would give the full path always or something?

Currently it is like this, if you compile this as "testprogram":

Code: Select all

ConsolePrint("Dir:", GetCurrentDirectory())
ConsolePrint("File:", GetFileArgument())
And then try to run it like this:

Code: Select all

System:> ram:testprogram MorphOS.readme
Dir: Ram Disk:
File: MorphOS.readme
Which means that currently the program can't know in which directory the file is located. In this case it can't know the file is located in the "System:" partition, and can't be used in further operations in the program.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Getting the "launch" dir

Post by airsoftsoftwair »

jPV wrote: Sat Mar 30, 2019 6:49 pm Maybe, if it would give the full path always or something?
Hmm, yeah, actually, I thought it would do just that but apparently it doesn't. So I guess I have to fix GetFileArgument() to return a fully qualified path because otherwise it doesn't make much sense, as illustrated by your case...
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Getting the "launch" dir

Post by airsoftsoftwair »

For compatibility reasons, I haven't changed the behaviour of GetFileArgument() but added an additional argument which, when set to TRUE, will return a fully-qualified path.

Code: Select all

- New: GetFileArgument() accepts an optional parameter now; if this is set to TRUE, GetFileArgument()
  will return the full path to the file
Post Reply