Page 1 of 1
GetCurrentDirectory give home directory
Posted: Mon Jun 30, 2014 3:28 pm
by John Duchek
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
Re: GetCurrentDirectory give home directory
Posted: Mon Jun 30, 2014 4:39 pm
by ts-soft
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:
Code: Select all
CurDir = GetPathPart(ProgramFilename())
Re: GetCurrentDirectory give home directory
Posted: Tue Jul 01, 2014 2:07 pm
by John Duchek
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
Re: GetCurrentDirectory give home directory
Posted: Tue Jul 01, 2014 2:17 pm
by John Duchek
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
Re: GetCurrentDirectory give home directory
Posted: Tue Jul 01, 2014 2:24 pm
by STARGÅTE
Compiler -> Options -> Compile/Run -> [x] Create temporary exe in the source directory
Re: GetCurrentDirectory give home directory
Posted: Tue Jul 01, 2014 3:23 pm
by John Duchek
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
Re: GetCurrentDirectory give home directory
Posted: Tue Jul 01, 2014 3:29 pm
by John Duchek
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?
Re: GetCurrentDirectory give home directory
Posted: Tue Jul 01, 2014 3:50 pm
by ts-soft
The best is to do what STARGÅTE say:
Compiler -> Options -> Compile/Run -> [x] Create temporary exe in the source directory
Re: GetCurrentDirectory give home directory
Posted: Wed Jul 02, 2014 1:43 pm
by John Duchek
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
Re: GetCurrentDirectory give home directory
Posted: Wed Jul 02, 2014 1:49 pm
by luis
John Duchek wrote:I tried that and it seems to work.
Oh, finally you set that option.
http://www.purebasic.fr/english/viewtop ... 58#p447458
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?
You have no guarantees.
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