Click to See Complete Forum and Search --> : Get Directory


programming fool
June 18th, 2001, 02:25 PM
How do you get the directory of the program you are currently running?

Ghost308
June 18th, 2001, 02:38 PM
Try using App.Path, let me know how it goes.

ant
June 18th, 2001, 02:56 PM
Msgbox App.path

--Ant
--------------------------------------------------
check out my newest freeware
E-mail me at: cgeorge@thevortex.com
for the address

programming fool
June 18th, 2001, 03:26 PM
Thanks! The only problem is I need to remove the executable name of the path. What is the substring function in VB? Or is there a string splice or something?

Ghost308
June 18th, 2001, 03:31 PM
You can use Mid(...), Right(...), and Left(...) similar to other languages. Since you know the length of the executable file name, you could use this to get the length of the string...


ExecLength = 'whatver the length of the .exe is
Dim x as Integer
x = Len(App.Path) - ExecLength
MyDirectory = Left(App.Path, x)


I haven't tested that but it seemed logical. Good luck!

Iouri
June 18th, 2001, 03:33 PM
Try this
' Retrieve a file's base name
' if the second argument is true, the result include the file's path

Function GetFileBaseName(FileName As String, Optional ByVal IncludePath As _
Boolean) As String
Dim i As Long, startPos As Long, endPos As Long

startPos = 1

For i = Len(FileName) To 1 Step -1
Select Case Mid$(FileName, i, 1)
Case "."
' we've found the extension
If IncludePath Then
' if we must return the path, we've done
GetFileBaseName = Left$(FileName, i - 1)
Exit Function
End If
' else, just take note of where the extension begins
If endPos = 0 Then endPos = i - 1
Case ":", "\"
If Not IncludePath Then startPos = i + 1
Exit For
End Select
Next

If endPos = 0 Then
' this file has no extension
GetFileBaseName = Mid$(FileName, startPos)
Else
GetFileBaseName = Mid$(FileName, startPos, endPos - startPos + 1)
End If
End Function




Iouri Boutchkine
iouri@hotsheet.com