Hello all
I've been trying to find out how to find the directory to the .exe file that is executing. Because when I use GetCurrentDirectory() I get the directory where the program is loaded from. Like when I right click on "textFile.txt" and choose "Open with..." and then select the .exe program, the current directory for the program will now be the directory for the "textFile.txt" and not the directory for the .exe program is in.
Thank you in advance.
Finding the directory where the .exe file is
Re: Finding the directory where the .exe file is
On Windows you are able to do it with the API:
GetModuleFileName_(#NULL)
or with standard PureBasic
GetModuleFileName_(#NULL)
or with standard PureBasic
Code: Select all
GetPathPart(ProgramFileName())
ThinkPad T61 | PureBasic 4.51 | Windows 7 (32) | Kubuntu 11.10 (64) | Syllable (32)
-
- Addict
- Posts: 1482
- Joined: Tue Feb 22, 2011 1:16 pm
Re: Finding the directory where the .exe file is
GetCurrentDirectory() doesn't relate to your exe's location; it relates to the directory that your exe is USING.
Here's an example which should make it clear. Make the following code a standalone executable, and run it.
Here's an example which should make it clear. Make the following code a standalone executable, and run it.
Code: Select all
exedir$=GetPathPart(ProgramFilename())
curdir$=GetCurrentDirectory()
MessageRequester("Test 1/2","Exe location: "+exedir$+#CR$+"Current Dir : "+curdir$)
SetCurrentDirectory("C:\Program Files\")
curdir$=GetCurrentDirectory()
MessageRequester("Test 2/2","Exe location: "+exedir$+#CR$+"Current Dir : "+curdir$)
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
PureBasic: Born in 1998 and still going strong to this very day!
Re: Finding the directory where the .exe file is
Alright when I use ProgramFilename() save the .exe file in some directory, and right click on a random file, and say "Open With...", and I choose my program that I just saved, the ProgramFilename() will now be the directory where the random file is placed????
Re: Finding the directory where the .exe file is
My bad it works. Thank you very much