Correct using of relative path on MacOS
Posted: Sun Jan 02, 2011 6:57 pm
Because of the problems on MacOS to find files in other directories than the executable, differences between running from the IDE and as executable I'm using the following procedure:
Do you know any easier way to handle relative paths on MacOS?
For example I want to load some images, which are completely outside of the directory containg the PB code. Here for example a (Windows compatible) path from a PB code in the CodeArchiv:
How can I easily use such relative paths ("../xyz") with resources in "above" directories also with PB for MacOS?
Code: Select all
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
CompilerIf #PB_Compiler_Debugger = 1 ; Debugger is on
path$ = #PB_Compiler_FilePath
CompilerElse ; Debugger is off (executable)
path$ = RemoveString(GetPathPart(ProgramFilename()),"YourApp.app/Contents/MacOS/") ; change 'YourApp' into the program name --> an example for a full path: /Users/geoworld/GeoWorld2/Developing/PureBasic0.app/Contents/MacOS/
CompilerEndIf
CompilerElse ; Windows
path$ = GetPathPart(ProgramFilename())
CompilerEndIf
; MessageRequester("Program Path =", path$)
For example I want to load some images, which are completely outside of the directory containg the PB code. Here for example a (Windows compatible) path from a PB code in the CodeArchiv:
Code: Select all
LoadImage(0,"..\Gfx\PureBasicLogoNew.png")