Results 1 to 7 of 7

Thread: Ho do I retrieve the path of my current working directory?

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Location
    Houston, TX
    Posts
    4

    Question Ho do I retrieve the path of my current working directory?

    I have this VB exe file in any given folder. When I execute it, I want for it to store the path in which it is saved.

    And also, I only want the path... I do NOT want the path + filename.

    I tried using CurDir, but that only returns the default path for Visual Basic.

    Example:


    Private Sub cmdCurrentPath_Click()

    MsgBox "The current path is: " + CurDir

    End Sub

    The message box will always say : C:\VC6\VB98

    Thanks.

  2. #2
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    app.path returns the path where the exe is running

    VB Code:
    1. msgbox app.path

  3. #3
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736

    Warning, if you are offended by the mention of FSO, do not read

    I will jump out of the way of the rocks that will be thrown my way, but one way to do it is with the FileSystemObject. Add the Microsoft Scripting Runtime to your project and use the following code.
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim fso As FileSystemObject
    3.     Set fso = New FileSystemObject
    4.    
    5.     MsgBox fso.GetParentFolderName(App.Path)
    6.     Set fso = Nothing
    7. End Sub

  4. #4
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    Why do people hate the FSO so much? Is it because of the reference?

  5. #5
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    Yes. "Some" programmers take offense to using FSO because it involves distributing an additional dll. But they do not hesitate to recommend using other controls that involve using dll's that are a lot larger than scrrun.dll.

    Go figure.

  6. #6
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    Why use FSO when u can just use app.Path???????????

    IS there any thing wrong with app.path? Please let me know!

  7. #7
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    The problem with app.path is that it does not use FSO .

    My fault, my fault. App.Path is a beautiful solution. When I answered the question I was working on a project where the folder name and the exe name were the same, so I should have paid attention to what I was doing. I mistakenly thought that app.path was including the exe name too.

    Sorry for the confusion. Besides, it is a Friday and I am just waiting to get out of here.

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