GetCurrentDirectory()

Mac OSX specific forum
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

GetCurrentDirectory()

Post 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
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Post 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.
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Post 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.
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Post 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: "/" . :?
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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 "/"
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Post 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.
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Post 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 :!:
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Post 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)
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
jamirokwai
Enthusiast
Enthusiast
Posts: 799
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Path to bundle.app

Post 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.
Regards,
JamiroKwai
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Post 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
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
Post Reply