What is the path returned by the CurDir function

New to FreeBASIC? Post your questions here.
Post Reply
SlugX
Posts: 4
Joined: Oct 31, 2024 2:10

What is the path returned by the CurDir function

Post by SlugX »

I thought it would return the current program's path, but I've used it and found that it often doesn't, sometimes it returns the "correct" path, sometimes it returns a different one, and I can't find any pattern to it 😂.
Gunslinger
Posts: 109
Joined: Mar 08, 2016 19:10
Location: The Netherlands

Re: What is the path returned by the CurDir function

Post by Gunslinger »

What OS are you using?
seems fine in windows 10 64bit
SlugX
Posts: 4
Joined: Oct 31, 2024 2:10

Re: What is the path returned by the CurDir function

Post by SlugX »

Gunslinger wrote: Nov 05, 2024 16:53 What OS are you using?
seems fine in windows 10 64bit
I'm using windows 11
hhr
Posts: 245
Joined: Nov 29, 2019 10:41

Re: What is the path returned by the CurDir function

Post by hhr »

Files are written or read in the current directory if you only enter the file name without the path.

Code: Select all

print "Path of the calling program:"
print "Exepath: ";exepath
print
print "Path of the current working directory:"
print "Curdir: ";curdir
print
print "Changing the current directory:"
chdir "C:\Windows"
print "Exepath: ";exepath
print "Curdir: ";curdir
sleep
SlugX
Posts: 4
Joined: Oct 31, 2024 2:10

Re: What is the path returned by the CurDir function

Post by SlugX »

hhr wrote: Nov 05, 2024 18:29 Files are written or read in the current directory if you only enter the file name without the path.

Code: Select all

print "Path of the calling program:"
print "Exepath: ";exepath
print
print "Path of the current working directory:"
print "Curdir: ";curdir
print
print "Changing the current directory:"
chdir "C:\Windows"
print "Exepath: ";exepath
print "Curdir: ";curdir
sleep
Thank you. Now I understand how theses functions work
D.J.Peters
Posts: 8616
Joined: May 28, 2005 3:28
Contact:

Re: What is the path returned by the CurDir function

Post by D.J.Peters »

ChDir(ExePath())
after this CurDir() points to the exe path also.

Joshy
marcov
Posts: 3489
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: What is the path returned by the CurDir function

Post by marcov »

Note that browsing in a file selection window might change the path again as do some other widgets like directoryselect.

You would need to check your program and redo this every time after you call such widget. I gave up on it, and always use craft absolute paths instead, and not rely on curdir at all in GUI apps.
Post Reply