GetCurrentDirectory

Linux specific forum
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

GetCurrentDirectory

Post by Polo »

Hello,

When I launch my code from the IDE, GetCurrentDirectory return the path where the .pb file is ("/media/hdd2/"), however, when I compile the executable and I launch it, GetCurrentDirectory return "/home/Account", however the directory of the executable is the same as the .pb file :?

This explains why no file can be loaded when I launch the executable, but how can I fix that ?

Cheers
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 »

If you run your executable in a shell, the current dir is not automatic
changed. Without setting a new path, the current dir is mostly the current
user dir.

Code: Select all

GetPathPart(ProgramFilename())
should help!
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
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

ts-soft wrote:If you run your executable in a shell, the current dir is not automatic
changed.
This behavior is normal ? I don't really see the use of getcurrentdirectory if it doesn't return the current directory, gethomedirectory would do then :)

Anyway thanks a lot, your workaround works great, but now only when I launch the executable, and not anymore when I click on launch from the ide...
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 »

> This behavior is normal ? Yes, is the same on windows, but you use allways a filemanager to run a program. This changes the currentdir :wink:

Code: Select all

Procedure.s GetExePath()
  Protected ExePath.s = GetPathPart(ProgramFilename())
  If LCase(ExePath) = LCase(GetTemporaryDirectory()) : ExePath = GetCurrentDirectory() : EndIf
  ProcedureReturn ExePath
EndProcedure
works on windows, linux with PB 4.1 and higher, with
default settings!

greetings
Thomas
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 »

I don't really see the use of getcurrentdirectory if it doesn't return the current directory
It does return the current directory. It just so happens that you don't know what the "current directory" is...
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Sorry not to be good enough for you.
Post Reply