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.
Getting the "launch" dir
- airsoftsoftwair
- Posts: 5443
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Getting the "launch" dir
Hmm, sounds like a job for GetFileArgument()?
Re: Getting the "launch" dir
Maybe, if it would give the full path always or something?
Currently it is like this, if you compile this as "testprogram":
And then try to run it like this:
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.
Currently it is like this, if you compile this as "testprogram":
Code: Select all
ConsolePrint("Dir:", GetCurrentDirectory())
ConsolePrint("File:", GetFileArgument())
Code: Select all
System:> ram:testprogram MorphOS.readme
Dir: Ram Disk:
File: MorphOS.readme
- airsoftsoftwair
- Posts: 5443
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Getting the "launch" dir
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...
- airsoftsoftwair
- Posts: 5443
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Getting the "launch" dir
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