How to get the exe directory

Share your advanced PureBasic knowledge/code with the community.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

How to get the exe directory

Post by Mistrel »

Here is a neat thing you can do if you ever get lost in your current directory. :roll:

Code: Select all

Define lpme.MODULEENTRY32

h=CreateToolhelp32Snapshot_($00000008,GetCurrentProcessId_())
lpme\dwSize=SizeOf(MODULEENTRY32)
Module32First_(h,@lpme)

For i=0 To 255
	module.s+Chr(lpme\szModule[i])
Next i

For i=0 To 259
	path.s+Chr(lpme\szExePath[i])
Next i

Debug module.s
Debug path.s
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Same result, less code:

Code: Select all

Filename$ = Space(#MAX_PATH)
GetModuleFileName_(0,Filename$,#MAX_PATH)
Debug GetFilePart(Filename$) : Debug Filename$
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

And even less code and natively:

Code: Select all

Debug ProgramFilename()
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

Thanks for the tip, Fluid Byte! :D
PB wrote:And even less code and natively:

Code: Select all

Debug ProgramFilename()
Less code, yes. But this doesn't return the value I need from within a dll.
Post Reply