GetCurrentDirectory()

Mac OSX specific forum
jamirokwai
Enthusiast
Enthusiast
Posts: 799
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Post by jamirokwai »

Danke, das ist noch besser :)
Thorsten1867 wrote: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
-----

Edit:
Hm. After doing some tests, does not work as expected. I use the line coded by Michael51,
which works better for me. I also extended the whole process to determine the
location on compile-time. See http://www.purebasic.fr/english/viewtopic.php?p=249534
Regards,
JamiroKwai
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Post by michel51 »

jamirokwai wrote:
Thorsten1867 wrote: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
-----

Edit:
Hm. After doing some tests, does not work as expected. I use the line coded by Michael51,
which works better for me. I also extended the whole process to determine the
location on compile-time.
I don't have tested the code above, but there is a different between the executable on Windows and the application on Mac. If you compile on Mac your code as "Application" (.app), then you will get a "folder". Your (unix-)-executable is saved in 'Contents/MacOS/'.
My code will return the path of the application.
I think, the code of Thosten1867 will return the path of the executable.

But I think, you know the different I told here. :)
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Post by Thorsten1867 »

I don't know, which path the Mac use, but you have only to change line 4 (If 'MacPath' ....).
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
KianV
User
User
Posts: 17
Joined: Thu Dec 26, 2019 3:31 pm

Re: GetCurrentDirectory()

Post by KianV »

I know that this is quite a specific case, but it matters when sharing programs.
I have used this code:

Code: Select all

   result$ = Left(GetPathPart(ProgramFilename()), FindString(GetPathPart(ProgramFilename()),GetFilePart(ProgramFilename())+".app",1)-1)
to get the directory where the program is stored.
This works fine when the program is compiled and I can run it from any directory.
If I then zip the file and upload it to a server, then download it to replace the original, I get this returned instead of the correct path:

/private/var/folders/90/7gn_ctsx0w5gffqnrypyq_y00000gn/T/AppTranslocation/8294524A-D59F-4FE2-AB7E-C98A971E0D7C/d/

Can anyone enlighten me as to what is going on?
User avatar
Piero
Addict
Addict
Posts: 1113
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Path to bundle.app

Post by Piero »

jamirokwai wrote: Tue Jun 24, 2008 9:31 amI desperately needed this.

Code: Select all

; Multilevel, Multiplatform Enclosing Folder (can optionally set Current Directory)
Procedure.s UpperDir(path$, level = 1, setcurrdir = #False)
   If FileSize(path$) = -1 : ProcedureReturn "" : EndIf
   Protected i, OLDcurrdir$ = GetCurrentDirectory()
   path$ = GetPathPart(path$) ; in case of file
   For i = 1 To level : path$ + ".." + #PS$ : Next
   SetCurrentDirectory(path$)
   path$ = GetCurrentDirectory()
   If Not setcurrdir : SetCurrentDirectory(OLDcurrdir$) : EndIf
   ProcedureReturn path$
EndProcedure

Debug UpperDir(ProgramFilename(),2)
Post Reply