|
-
June 18th, 2001, 02:25 PM
#1
Get Directory
How do you get the directory of the program you are currently running?
-
June 18th, 2001, 02:38 PM
#2
Re: Get Directory
Try using App.Path, let me know how it goes.
-
June 18th, 2001, 02:56 PM
#3
Re: Get Directory
Msgbox App.path
--Ant
--------------------------------------------------
check out my newest freeware
E-mail me at: [email protected]
for the address
-
June 18th, 2001, 03:26 PM
#4
Re: Get Directory
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?
-
June 18th, 2001, 03:31 PM
#5
Re: Get Directory
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!
-
June 18th, 2001, 03:33 PM
#6
Re: Get Directory
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
[email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|