Page 2 of 2
Posted: Tue Jun 24, 2008 9:57 pm
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
Posted: Thu Jun 26, 2008 11:40 pm
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.

Posted: Fri Jun 27, 2008 3:59 pm
by Thorsten1867
I don't know, which path the Mac use, but you have only to change line 4 (If 'MacPath' ....).
Re: GetCurrentDirectory()
Posted: Thu Dec 04, 2025 7:12 am
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?
Re: Path to bundle.app
Posted: Thu Dec 04, 2025 3:22 pm
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)