Mac OSX - GetCurrentDirectory problem.

Just starting out? Need help? Post your questions and find answers here.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Mac OSX - GetCurrentDirectory problem.

Post by davido »

I have directory which contains the code and it's compiled app.
Compiling the code from the IDE is fine; the GetCurrentDirectory is the Directory where the code resides.
If I run the app which is in the same directory; GetCurrentDirectory changes:

When compiled by IDE : Current Directory = /Users/Ztesting/

Compiled code and CDir_Test.app saved in /Users/Ztesting/
Running CDir_Test.app : Current Directory = CDir_Test.app/Contents/[/code]

This doesn't seem right; can anyone explain, please.

Code: Select all

MessageRequester("Display CurrentDirectory",GetCurrentDirectory())
Debug GetCurrentDirectory()

;When compiled by IDE : Current Directory = /Users/Ztesting/

; Compiled code and CDir_Test.app saved in /Users/Ztesting/
; running CDir_Test.app : Current Directory = CDir_Test.app/Contents/
Purebasic 5.70LTS
DE AA EB
infratec
Always Here
Always Here
Posts: 6866
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Mac OSX - GetCurrentDirectory problem.

Post by infratec »

GetCurrentDirectory() returns not the directory of your executable.
Else what happen when you use SetCurrentDirectory() :?:
Does it move your exceutable :wink:

For the directory of the executable you have to use:

Code: Select all

GetPathPart(ProgramFilename())
User avatar
mk-soft
Always Here
Always Here
Posts: 5386
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Mac OSX - GetCurrentDirectory problem.

Post by mk-soft »

GetCurrentDirectory is not always fixed during startup.
It depends on where the program is started from.

For example without saving it.
Path: '/Users/Michael/Applications/Purebasic v5.72-X64/PureBasic.app/Contents/'.

Saved.
Path '/Users/Michael/Data/Purebasic/Ablage/TestApp.app/Contents/'.

It is better to work with ProgramFileName

Tipp
- Pack all resources into the App

Link: MyAppData
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Mac OSX - GetCurrentDirectory problem.

Post by davido »

@infratec
@mk-soft
Thank you for your assistance some very useful information.

Unfortunately I didn't pose my query very well, sorry. :oops:

What I am trying to do is to get the directory where the app resides.
I've decided to use a work-around when running under OSX: I just adjust the path back two levels.
DE AA EB
User avatar
mk-soft
Always Here
Always Here
Posts: 5386
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Mac OSX - GetCurrentDirectory problem.

Post by mk-soft »

This is right because you have to go up two levels.

BUT... Nothing that belongs there belongs to the APP.

Everything that belongs to the APP goes in the folder "MyAPP.app/Contents/Resources. Icons, Pictures, Static Data, etc
For your own libraries I use, against other things, the folder "MyAPP.app/Contents/Library.

For Runtime Data uses "GetUserDirectory(#PB_Directory_ProgramData) + "YourCompanyName/YourAppName/Files.cfg"
Example https://www.purebasic.fr/english/viewto ... 12#p550109
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply