GetCurrentDirectory give home directory
-
- User
- Posts: 83
- Joined: Mon May 16, 2005 4:19 pm
- Location: St. Louis, MO
GetCurrentDirectory give home directory
I am running 5.22 LTS (x64) under fedora linux. Many of my programs are trashing as I normally put my data files in the same directory as the source code.
For example, I have a program in /home/jduchek/source_Pure/2014-Pure_SC_updated/Best_300_software/
The program's name is file_read_sample.pb.
If I ask in the program, what my current directory is I get
Debug GetCurrentDirectory()
/home/jduchek
If I ask for the home directory I get
Debug GetHomeDirectory()
/home/jduchek
I would think the current directory would be the one with the source code in it.
Is this a bug, or is there another way to access the current working directory?
John
For example, I have a program in /home/jduchek/source_Pure/2014-Pure_SC_updated/Best_300_software/
The program's name is file_read_sample.pb.
If I ask in the program, what my current directory is I get
Debug GetCurrentDirectory()
/home/jduchek
If I ask for the home directory I get
Debug GetHomeDirectory()
/home/jduchek
I would think the current directory would be the one with the source code in it.
Is this a bug, or is there another way to access the current working directory?
John
John R. Duchek
St. Louis,MO
St. Louis,MO
Re: GetCurrentDirectory give home directory
CurrentDirectory have nothing to do with your source-directory.
CurrentDirectory is the dir, you have set or your application have set
or any other directory.
You have to set the currentdirectory!
The pb-ide set the currentdirectory to the sourcepath, but if you not
using, the pb ide, the path is not set. Some fileexplorer set the current-
directory, but if you use a shell, the path is not set!
To make sure, your application use the right path, you have to add:
CurrentDirectory is the dir, you have set or your application have set
or any other directory.
You have to set the currentdirectory!
The pb-ide set the currentdirectory to the sourcepath, but if you not
using, the pb ide, the path is not set. Some fileexplorer set the current-
directory, but if you use a shell, the path is not set!
To make sure, your application use the right path, you have to add:
Code: Select all
CurDir = GetPathPart(ProgramFilename())
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.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

-
- User
- Posts: 83
- Joined: Mon May 16, 2005 4:19 pm
- Location: St. Louis, MO
Re: GetCurrentDirectory give home directory
ts-soft,
Thank you for your reply. That seems like a rather strange way to do things, but as long as I understand how to handle the situation I am good to go.
I appreciate your explanation.
John
Thank you for your reply. That seems like a rather strange way to do things, but as long as I understand how to handle the situation I am good to go.
I appreciate your explanation.
John
John R. Duchek
St. Louis,MO
St. Louis,MO
-
- User
- Posts: 83
- Joined: Mon May 16, 2005 4:19 pm
- Location: St. Louis, MO
Re: GetCurrentDirectory give home directory
Well that doesn't seem to work.
CurDir.s = GetPathPart(ProgramFilename())
Debug CurDir
gives me CurDir as /tmp/
My program file isn't in /tmp/
John
CurDir.s = GetPathPart(ProgramFilename())
Debug CurDir
gives me CurDir as /tmp/
My program file isn't in /tmp/
John
John R. Duchek
St. Louis,MO
St. Louis,MO
Re: GetCurrentDirectory give home directory
Compiler -> Options -> Compile/Run -> [x] Create temporary exe in the source directory
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
-
- User
- Posts: 83
- Joined: Mon May 16, 2005 4:19 pm
- Location: St. Louis, MO
Re: GetCurrentDirectory give home directory
No, this was my bad. I used the data file name, not the program file name. I will recheck it out.
I don't need to create a exe file (besides it is linux), I need to access a datafile in the same directory as the program file.
Thanks all,
John
I don't need to create a exe file (besides it is linux), I need to access a datafile in the same directory as the program file.
Thanks all,
John
John R. Duchek
St. Louis,MO
St. Louis,MO
-
- User
- Posts: 83
- Joined: Mon May 16, 2005 4:19 pm
- Location: St. Louis, MO
Re: GetCurrentDirectory give home directory
Not my bad. This explains why I think there is something screwy here. My filename is file_read_sample.pb
Here is what I am getting
Debug CurDir
Debug ProgramFilename()
/tmp/
/tmp/purebasic_compilation0.out
So my ProgramFileName() is purebasic_compilation0.out
and it is in the tmp directory, not the directory that my sourcecode is in.
I still need for the program to come back with the directory that my sourcecode is in. How do I do it?
Here is what I am getting
Debug CurDir
Debug ProgramFilename()
/tmp/
/tmp/purebasic_compilation0.out
So my ProgramFileName() is purebasic_compilation0.out
and it is in the tmp directory, not the directory that my sourcecode is in.
I still need for the program to come back with the directory that my sourcecode is in. How do I do it?
John R. Duchek
St. Louis,MO
St. Louis,MO
Re: GetCurrentDirectory give home directory
The best is to do what STARGÅTE say:
Compiler -> Options -> Compile/Run -> [x] Create temporary exe in the source directory
Compiler -> Options -> Compile/Run -> [x] Create temporary exe in the source directory
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.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

-
- User
- Posts: 83
- Joined: Mon May 16, 2005 4:19 pm
- Location: St. Louis, MO
Re: GetCurrentDirectory give home directory
Ok. I tried that and it seems to work. What directory will the program be looking for the data in when permanently make an executable file? Will it look in the same directory that the executable is in?
Thanks,
John
Thanks,
John
John R. Duchek
St. Louis,MO
St. Louis,MO
Re: GetCurrentDirectory give home directory
Oh, finally you set that option.John Duchek wrote:I tried that and it seems to work.

http://www.purebasic.fr/english/viewtop ... 58#p447458
You have no guarantees.John Duchek wrote: What directory will the program be looking for the data in when permanently make an executable file? Will it look in the same directory that the executable is in?
Use SetCurrentDirectory() to the same dir your exe has been launched from and then use relative paths from there,
or use absolute paths building them from the position your exe has been launched from,
in any case you need something like this
http://www.purebasic.fr/english/viewtop ... 98#p447398
to know where you are in the filesystem
"Have you tried turning it off and on again ?"
A little PureBasic review
A little PureBasic review