program path$ or default dir$?
program path$ or default dir$?
I am writing a program called material.exe
if I drop it in a directory called c:\material
Is there a command that'll put that directory into a variable with out having to hard code it into the program or putting it into a config file?
ie. program_path$ = ???
or default_dir$ = ???
Thanks,
Mike...
if I drop it in a directory called c:\material
Is there a command that'll put that directory into a variable with out having to hard code it into the program or putting it into a config file?
ie. program_path$ = ???
or default_dir$ = ???
Thanks,
Mike...
Re: program path$ or default dir$?
Hi,
Choose the one you need
Bernd
Code: Select all
Debug GetPathPart(ProgramFilename())
Debug GetCurrentDirectory()
Debug GetTemporaryDirectory()
Debug GetHomeDirectory()

Bernd
Re: program path$ or default dir$?
GetCurrentDirectory() is the one I needed.
Thanks
Mike...
Thanks
Mike...
Re: program path$ or default dir$?
Better use: GetPathPart(ProgramFilename())mikeschn wrote:GetCurrentDirectory() is the one I needed.
This one is always the path to you're exe.
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.

-
- Addict
- Posts: 4779
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: program path$ or default dir$?
Only
reliably yields the directory for which mikeschn has asked in his first post.
Code: Select all
GetPathPart(ProgramFilename())
Then you didn't describe your requirements properly in your first post.mikeschn wrote:GetCurrentDirectory() is the one I needed.
Re: program path$ or default dir$?
I guess I'd better use
since I do need the path to my exe file...
Thanks again!
Mike...
Code: Select all
GetPathPart(ProgramFilename()
Thanks again!
Mike...
Re: program path$ or default dir$?
It's a false belief that GetCurrentDirectory() always returns the path of your exe.
It can change under certain specific circumstances. Use ProgramFilename() instead.
It can change under certain specific circumstances. Use ProgramFilename() instead.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: program path$ or default dir$?
I just changed my program from
to
Now I find it drops the file in c:\users\Mike\AppData\Local
instead of c:\users\mike\documents\myprogram
I am not running from the .exe file. I am running from the Purebasic IDE.
Any thoughts why this is happening?
Thanks,
Mike...
Code: Select all
CreateFile(4,GetCurrentDirectory()+struct_Filename$)
Code: Select all
CreateFile(4,GetPathPart(ProgramFilename())+struct_Filename$)
instead of c:\users\mike\documents\myprogram
I am not running from the .exe file. I am running from the Purebasic IDE.
Any thoughts why this is happening?
Thanks,
Mike...
Re: program path$ or default dir$?
It happens because you are running a temporary file created by the IDE. Guess where the IDE's temp file was stored?mikeschn wrote:I just changed my program fromtoCode: Select all
CreateFile(4,GetCurrentDirectory()+struct_Filename$)
Now I find it drops the file in c:\users\Mike\AppData\LocalCode: Select all
CreateFile(4,GetPathPart(ProgramFilename())+struct_Filename$)
instead of c:\users\mike\documents\myprogram
I am not running from the .exe file. I am running from the Purebasic IDE.
Any thoughts why this is happening?
This will happen until you create an executible to run from a different location. If you already know this location you can use a predefined path to it while you are debugging the file and then replace it with 'GetPathPart(ProgramFilename())' just before you create the executible.
Re: program path$ or default dir$?
Demivec is right. Running from the IDE will give a different result to a standalone exe.
Here's how I handle it in my apps. This sets the global variables correctly no matter
if I run it with F5 from the IDE, or as a standalone executable when my app is done.
Just stick it at the top of your source and you're set; no further changes needed.
Here's how I handle it in my apps. This sets the global variables correctly no matter
if I run it with F5 from the IDE, or as a standalone executable when my app is done.
Just stick it at the top of your source and you're set; no further changes needed.
Code: Select all
Global appname$=ProgramFilename(),appdir$=GetPathPart(appname$)
CompilerIf #PB_Compiler_Debugger
appdir$=#PB_Compiler_FilePath
appname$=appdir$+"MyAppName.exe"
CompilerEndIf
Global appexe$=LCase(GetFilePart(appname$))
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.