The following cross-platform example checks if a file exists. I have tested it succesfully on these operating systems:
- Linux Mint 18 'Sarah' x86 with PB 5.44 x86 with GTK2 and GTK3 in ASCII and Unicode mode
- Lubuntu 14.04 x86 with PB 5.44 x86 with GTK2 and GTK3 in ASCII and Unicode mode
- MacOS 10.6.8 'Snow Leopard with PB 5.44 x86 in ASCII and Unicode mode
- Windows XP SP3 x86 with PB 5.44 x86 in ASCII and Unicode mode
- Windows 7 SP1 x64 with PB 5.44 x86 and x64 in ASCII and Unicode mode
- Windows 8.1 x64 with PB 5.44 x86 and x64 in ASCII and Unicode mode
Code: Select all
Procedure.I FileExists(Filename.S)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
ProcedureReturn PathFileExists_(Filename)
CompilerCase #PB_OS_Linux
Protected UTF8Filename.S = Space(StringByteLength(Filename, #PB_UTF8) + 1)
PokeS(@UTF8Filename, Filename, -1, #PB_UTF8)
ProcedureReturn g_file_test_(UTF8Filename, #G_FILE_TEST_EXISTS)
CompilerCase #PB_OS_MacOS
ProcedureReturn CocoaMessage(0, CocoaMessage(0, 0,
"NSFileManager defaultManager"),
"fileExistsAtPath:$", @Filename)
CompilerEndSelect
EndProcedure
; ----- Output on Linux and MacOS: 0, Windows: 1
Debug "FileExists: " + FileExists(#PB_Compiler_Home + "Compilers/PBCompiler.Exe")
; ----- Output on Linux and MacOS: 1, Windows: 0
Debug "FileExists: " + FileExists(#PB_Compiler_Home + "compilers/pbcompiler")