CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Get Directory

  1. #1

    Get Directory

    How do you get the directory of the program you are currently running?


  2. #2
    Join Date
    Jun 2001
    Location
    Memphis, TN
    Posts
    146

    Re: Get Directory

    Try using App.Path, let me know how it goes.


  3. #3
    Join Date
    May 2001
    Posts
    155

    Re: Get Directory

    Msgbox App.path

    --Ant
    --------------------------------------------------
    check out my newest freeware
    E-mail me at: [email protected]
    for the address

  4. #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?


  5. #5
    Join Date
    Jun 2001
    Location
    Memphis, TN
    Posts
    146

    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!



  6. #6
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    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]
    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
  •  





Click Here to Expand Forum to Full Width

Featured