How to get the full path of the current executable file in VB?
Asked Answered
A

1

17

I have created one windows application using VB. Whenever I executing the exe, I want to get the current directory of the exe file programatically.

For example,

Now, I am executing the exe file in d:\myApp\test.exe. Whenever I double click the exe file I want to get the path of the exe file like d:\myApp\test.exe.

Also, suppose, my exe is in CD or any memory stick, will it also get the path of the exe file?

I don't know is this possible or not?

Any suggestion?

Appulse answered 14/9, 2012 at 11:42 Comment(2)
Just to clarify, you're asking about how to get the path to the executable, not the current, working directory which is different.Heavyfooted
@Heavyfooted : yes Deanna you are right...i am asking about get the path to the executable... thanksAppulse
T
41

Try App.Path. It will give you the current exe path. To get exe name you can use App.EXEName. Note that App.Path will contain the trailing \ when in the root of a drive so any extra \ will need to be added conditionally.

So to get full path with exe name try this:

App.Path & IIf(Right$(App.Path, 1) <> "\", "\", "") & App.EXEName & ".exe"

Also, It will give you CD or any memory stick's path too.

Telesis answered 14/9, 2012 at 11:44 Comment(1)
If you use these in the IDE, you will get the path and the filename (minus the .vbp extension) of the project file.The

© 2022 - 2024 — McMap. All rights reserved.