Page 1 of 1

GetCurrentDirectory

Posted: Sat May 24, 2008 11:44 am
by Polo
Hello,

When I launch my code from the IDE, GetCurrentDirectory return the path where the .pb file is ("/media/hdd2/"), however, when I compile the executable and I launch it, GetCurrentDirectory return "/home/Account", however the directory of the executable is the same as the .pb file :?

This explains why no file can be loaded when I launch the executable, but how can I fix that ?

Cheers

Posted: Sat May 24, 2008 11:57 am
by ts-soft
If you run your executable in a shell, the current dir is not automatic
changed. Without setting a new path, the current dir is mostly the current
user dir.

Code: Select all

GetPathPart(ProgramFilename())
should help!

Posted: Sat May 24, 2008 12:02 pm
by Polo
ts-soft wrote:If you run your executable in a shell, the current dir is not automatic
changed.
This behavior is normal ? I don't really see the use of getcurrentdirectory if it doesn't return the current directory, gethomedirectory would do then :)

Anyway thanks a lot, your workaround works great, but now only when I launch the executable, and not anymore when I click on launch from the ide...

Posted: Sat May 24, 2008 12:22 pm
by ts-soft
> This behavior is normal ? Yes, is the same on windows, but you use allways a filemanager to run a program. This changes the currentdir :wink:

Code: Select all

Procedure.s GetExePath()
  Protected ExePath.s = GetPathPart(ProgramFilename())
  If LCase(ExePath) = LCase(GetTemporaryDirectory()) : ExePath = GetCurrentDirectory() : EndIf
  ProcedureReturn ExePath
EndProcedure
works on windows, linux with PB 4.1 and higher, with
default settings!

greetings
Thomas

Posted: Sat May 24, 2008 12:26 pm
by Trond
I don't really see the use of getcurrentdirectory if it doesn't return the current directory
It does return the current directory. It just so happens that you don't know what the "current directory" is...

Posted: Sat May 24, 2008 12:48 pm
by Polo
Sorry not to be good enough for you.