Barb0400
asked on
Get current path
How can I get the path that my program is running from upon running my program?
Of course you will have to probably compile your program first.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Vinny is correct :)
Yes I agree with Dave_Greene that Vinny is right, I have just tried out my suggestion and I now realise that there is no 'path' property for form1.
Sorry
Sorry
Use this win32 API to get the current directory
Public Declare Function GetCurrentDirectory Lib "kernel32" Alias "GetCurrentDirectory" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Hope this solves ur problem.
Public Declare Function GetCurrentDirectory Lib "kernel32" Alias "GetCurrentDirectory" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Hope this solves ur problem.
What I do is to declare a global AppPath variable and then use the following code right near the program start...
AppPath = App.Path
If Right$(AppPath,1)="\" Then
AppPath = Left$(AppPath,Len(AppPath) -1)
End IF
The reason for this being that if your program is running from root directory, such as C:\, then normal app.path returns "C:" only and so will muck up any usage of AppPath and backslashes in the rest of your program.
You can get the current operational directory using CurDir(), and change this if necessary with ChDir to your path.
For references to files etc. always use AppPath & "\FileName.ext" or AppPath & "\Directory\FileName.ext"
AppPath = App.Path
If Right$(AppPath,1)="\" Then
AppPath = Left$(AppPath,Len(AppPath)
End IF
The reason for this being that if your program is running from root directory, such as C:\, then normal app.path returns "C:" only and so will muck up any usage of AppPath and backslashes in the rest of your program.
You can get the current operational directory using CurDir(), and change this if necessary with ChDir to your path.
For references to files etc. always use AppPath & "\FileName.ext" or AppPath & "\Directory\FileName.ext"
Peter, you have been around this forum long enough to know that you shouldn't be proposing answers to questions... especially when your suggestion has already been commented in this thread. Barb, please reject Peters proposed answer.
Dave
Dave
The only other thing I would add is to keep in mind that App.Path == CurDir at the startup of your application if you run it by double clicking on the EXE file in a Windows Explorer or if started by a shortcut that has same directory in the Start In field of the properties page. Otherwise they will be different based on the value of the Start In field. The CurDir will be the path in that field or the directory that the shortcut is stored in if left blank.
Regards,
eeevans
Regards,
eeevans
"you shouldn't be proposing answers to questions"
Well, sorry, I'll refrain from posting anything in future !
App.Path had been commented on, but not the problem with the backslash, neither had CurDir been mentioned.
Well, sorry, I'll refrain from posting anything in future !
App.Path had been commented on, but not the problem with the backslash, neither had CurDir been mentioned.
Peter I'm not trying to brow beat you into not posting comments. Please do!!! but when you post your comment as "THE ANSWER", it moves the question to the locked area, where it gets less visibility, and is basically a dis-service to the question asker.
No hard feelings my friend!
-Dave
No hard feelings my friend!
-Dave
Apologise, I wasn't aware of the loss of visibility to a question's status on providing a possible answer. Will leave such as comments in future.
form1.caption =form1.path