Page 1 of 2

GetCurrentDirectory()

Posted: Fri Jun 06, 2008 9:50 pm
by michel51
This line

Code: Select all

Result$ = GetCurrentDirectory()
gets the actual directory name, if I compile from IDE.

But if I compile as a application ("test.app"), then the result is "/", the root directory on Mac.

I think, this is a bug, because the command was running on PB V 3.92.

BTW: The same results on V 4.10

Posted: Fri Jun 06, 2008 10:00 pm
by ts-soft
The CurrentDirectory and the Application Path not allways the same!

Use:

Code: Select all

Result$ = GetPathPart(ProgramFilename())
I think this is required.

Posted: Fri Jun 06, 2008 10:25 pm
by michel51
ts-soft wrote:The CurrentDirectory and the Application Path not allways the same!

Use:

Code: Select all

Result$ = GetPathPart(ProgramFilename())
I think this is required.
But the result is not the directory of the application :!:
On Mac the "Application" is a folder (bundle) with 'contents/MacOs/' and therein the compiled (unix-) executable.

And I will get the bundlepath.
I remember that on PB V 3.92 the command "GetCurrentDirectory()" returns the right path.

Posted: Sat Jun 07, 2008 9:22 am
by Trond

Posted: Sat Jun 07, 2008 7:10 pm
by michel51
Ok, here again a short assertion of my problem.

In the middle of 2007 I compiled a testfile with PB V 3.94.
A part of the code is here:

Code: Select all

   MessageRequester("Current Directory", GetCurrentDirectory())
   MessageRequester("Programmname", ProgramFilename())     
   MessageRequester("Nur Pfad: ",GetPathPart(ProgramFilename()))     
   MessageRequester("Nur File: ",GetFilePart(ProgramFilename()))      
   epos.l=FindString(GetCurrentDirectory(),GetFilePart(ProgramFilename())+".app",1)
   MessageRequester("Bundle-Pfad", Left(GetCurrentDirectory(), epos-1))
This application is saved in "/Users/Klaus/Programmieren/purebasic_Code/Test/"

The requester are showing the following results (from above downward)

Code: Select all

/Users/Klaus/Programmieren/purebasic_Code/Test/compilertest.app/Contents/
/Users/Klaus/Programmieren/purebasic_Code/Test/compilertest.app/Contents/MacOs/compilertest
/Users/Klaus/Programmieren/purebasic_Code/Test/compilertest.app/Contents/MacOs/
compilertest
/Users/Klaus/Programmieren/purebasic_Code/Test/
This shows unique that the command 'GetCurrentDirectory()' has been worked fine and correctly with V 3.94.
And if I move the application into another folder, the results are like it to be are.

But now (V. 4.10 and 4.20) the result of 'GetCurrentDirectory()' is "/" :!: :!:
And that is surely not correct :?
That's why I think it's a bug.

Posted: Sat Jun 07, 2008 7:26 pm
by ts-soft
> And that is surely not correct :?
Is correct. CurrentDirectory is the currently setting Path for your Application,
but you haven't set any Path, so the path is unassigned

Posted: Sat Jun 07, 2008 7:40 pm
by michel51
ts-soft wrote:> And that is surely not correct :?
Is correct. CurrentDirectory is the currently setting Path for your Application,
but you haven't set any Path, so the path is unassigned
And where i have to set this path?
Now I have set the current directory in preferences to "/Users/Klaus/Progammieren/purebasic_Code/",
restarted PureBasic and compiled a new one - but the result is the same:
GetCurrentDirectory() --> result: "/" . :?

Posted: Sat Jun 07, 2008 7:47 pm
by ts-soft
> And where i have to set this path?

Code: Select all

SetCurrentDirectory("what ever you want as current directory")
In some situations, the creating process set the path, for example the pb-ide
or the filemanager, but if none set the path, the path is on your os "/"

Posted: Sat Jun 07, 2008 8:05 pm
by michel51
ts-soft wrote:> And where i have to set this path?

Code: Select all

SetCurrentDirectory("what ever you want as current directory")
In some situations, the creating process set the path, for example the pb-ide
or the filemanager, but if none set the path, the path is on your os "/"
Hm..., then in PB is changed something. I don't have changed my system, is the same Mac Os X as before. And with PB V. 3.94 I never had used the command 'SetCurrentDirectory()'.
I agree, that in some situation the setting of the path is necesserily, but I never had done it in this way.
Nevertheless the application - compiled with 3.94 - outputs the correct values.

Posted: Sat Jun 07, 2008 8:10 pm
by ts-soft
> Nevertheless the application - compiled with 3.94 - outputs the correct values.
All versions have the right output, but pb have something changed, but this
is not a bug. You misinterpret what currenddirectory is!

Posted: Sat Jun 07, 2008 8:58 pm
by Trond
And that is surely not correct
That's why I think it's a bug.
Which tells me you didn't read my link.

This is very rude, but proved effective in another topic:
It does return the current directory. It just so happens that you don't know what the "current directory" is...
If you had read my link I wouldn't have had to be so rude. Or maybe if I was just a nicer person I wouldn't have said anything.

Posted: Sat Jun 07, 2008 9:28 pm
by michel51
Trond wrote:
Which tells me you didn't read my link.
Sorry, Trond, I did not want to insult anybody.
I've read the link, but not to the end. In Fred's posting I found a declaration and now I hope, I understood it.
May be, there was a 'translation error' into german or something else.

But when there was such a changing from version 3.94 to 4.x, then it could be, that a few codes are not running correct without a lot of changing :wink:

Thanks to all for help :!:

Posted: Sat Jun 07, 2008 10:40 pm
by michel51
I solved my problem :D
This line returns the 'bundlepath' of a application, where it is also stored.

Code: Select all

   result$ = Left(GetPathPart(ProgramFilename()), FindString(GetPathPart(ProgramFilename()),GetFilePart(ProgramFilename())+".app",1)-1)

Path to bundle.app

Posted: Tue Jun 24, 2008 9:31 am
by jamirokwai
michel51 wrote:I solved my problem :D
This line returns the 'bundlepath' of a application, where it is also stored.

Code: Select all

   result$ = Left(GetPathPart(ProgramFilename()), FindString(GetPathPart(ProgramFilename()),GetFilePart(ProgramFilename())+".app",1)-1)
Many thanking, I desperately needed this.

Posted: Tue Jun 24, 2008 4:53 pm
by Thorsten1867
I use this for my programs:

Code: Select all

Procedure.s GetProgramDirectory() ; Program Path
  Protected ProgDir.s
  ProgDir = GetPathPart(ProgramFilename())
  If ProgDir = #PB_Compiler_Home+"Compilers\" Or ProgDir = GetTemporaryDirectory()
    ProgDir = GetCurrentDirectory()
  EndIf
  ProcedureReturn ProgDir
EndProcedure