[Implemented] GetWorkingDirectory()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

[Implemented] GetWorkingDirectory()

Post by Num3 »

This command would be very usefull for Linux, cause Linux depends a lot on other directories to store data and libraries, but unlike windows it does not seek the directory where the executable was launch itself :(
zikitrake
Addict
Addict
Posts: 868
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

hope that this code helps you.

put it at the beginning of the program

Code: Select all

Global workdir$
workdir$=Space(255) : GetCurrentDirectory_(255,@workdir$)
...
(your code)
PB 6.21 beta, PureVision User
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

zikitrake wrote:

Code: Select all

Global workdir$
workdir$=Space(255) : GetCurrentDirectory_(255,@workdir$)
...
(your code)
On Linux??!?
zikitrake
Addict
Addict
Posts: 868
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Post by zikitrake »

:oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops:

Sorry!!!, I need to learn english language more and more
PB 6.21 beta, PureVision User
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

:wink:
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

Again..
If Someone is interested:
*EDIT Removed link (server down)

GetCurrentDirectory() For Linux, return a string
Download, rename and copy to purelibraries & test :wink:

Hope it works.. Just a quick lib I made..
Last edited by olejr on Mon Sep 13, 2004 6:32 pm, edited 1 time in total.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

olejr wrote:Again..
If Someone is interested:
http://v3.homeip.net/getdir

GetCurrentDirectory() For Linux, return a string
Download, rename and copy to purelibraries & test :wink:

Hope it works.. Just a quick lib I made..
What!?

User libs for Linux !?!?!? 8O
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

Yes...
Have you tried it....?
It's my first 'test library'
And when I wrote rename,
that's incase it was downloaded as .txt.....

It would be nice to have the userlibraries folder
under purelibraries, so the 'root folder' could
stay clean.. Like Windows..
Kazmirzak
User
User
Posts: 92
Joined: Fri Jun 18, 2004 5:44 pm
Location: Germany

Post by Kazmirzak »

There are many problems with the current directory: In windows, the current directory is the directory of the file you loaded, for example if you doubleclick onto a .bmp and you have written a Bitmap-Editor associated with it, so your current directory will be the directory of the .bmp and not the directory of your executable!!

Ok, you say, let's determine the directory of the .exe - yeah, you will get the Compilers - Directory of your PureBasic installation. In my mind this is a bug, because the .exe should be compiled there where your source code is, because there would be the end-users .exe, but this should be soved by the Pure Basic team.

I think these Problems are just the same with Linux, so even if Linux supports some kind of 'Current Directory', I can't promise that you will get that string that you are really searchin for.
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

I'm understand what you say, but the question was:
How to get the directory where the executable was launched...

And the function in the library I created, return the path to the
launched exe, not the compiler.. That would be /usr/bin
anyway. If you followed the standard install....

Example: If your source is /home/blah/project/test.pb
And you compile this, my function return
/home/blah/project
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Agreed, this function is needed, as long a GetHomeDirectory() which would returns 'Documents & setting\username\' on windows and '/usr/username' on linux & co. GetTemporaryDirectory() sounds useful too. If some other are needed, just tell. I bet than SetCurrentDirectory() is needed too.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

I bet than SetCurrentDirectory() is needed too.
Yeah and GetCurrentDirectory() too. :wink:

Also what about making a command take constants like this:

Code: Select all

String.s = GetDirectory(#PB_Current_Directory)
String.s = SetDirectory(#PB_Current_Directory)
String.s = GetDirectory(#PB_Temp_Directory)
String.s = GetDirectory(#PB_Home_Directory)
;etc...
--Kale

Image
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post by GreenGiant »

I like Kale's idea. It could be extended with #PB_Windows_Directory, #PB_ProgramFiles_Directory, #PB_TempFiles_Directory (as in the system temp files folder) and #PB_CurrentUser_Directory for windows and the equivalent directories for linux. Not really needed, it'd just make it quick and easy to get all the system folders.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

SetDirectory() would be only for the Current one then. Strange to have a generic command only for one purpose. I think I will stick to the 'portable' directory functions, as described above. Thank you for the suggestion tough !
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

The constant naming should be the other way around though, to stick to the PB constant naming ;)

#PB_Directory_Home
#PB_Directory_Current
quidquid Latine dictum sit altum videtur
Post Reply