Results 1 to 7 of 7

Thread: app.path question

  1. #1

    Thread Starter
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305
    i've wanted to know how to get the directory of a program using the app.path command ... how would i go about it?

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    using app.path

    Dim AppPath$

    If Right(App.Path, 1) <> "\" Then _
    AppPath = App.Path & "\" _
    Else AppPath = App.Path

    End If

    use this when you store all your app files in one dir
    then when calling a file you simpley say

    Open AppPath & Myfile.txt for append as # 1

    that way..if the folder is stored on another pc
    under D:\yourstuff\mystuff\xyz
    the application will find it cause it looks for
    myfile.txt in the app path which is the path where
    the folder is stored..

    Yea...hopefully I haven't confused you to death..
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3

    Thread Starter
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305

    lol

    u lost me after dim apppath$

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    If by "directory of a program" you mean the folder where the program is installed, then assuming that the program is installed in c:\xyz then

    MsgBox App.Path & "\" & "myfile.txt" would display

    c:\xyz\myfile.txt

  5. #5
    Lively Member
    Join Date
    Jun 2000
    Posts
    82
    HeSaidJoe had a few extra lines in his code to make sure if the app is in the root folder, it wouldn't return "C:\\" instead of "C:\"
    It's safer that way.
    Andrew Empson
    vb6(ent) SP4

  6. #6

    Thread Starter
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305

    i just want to know

    i just want to know the directory of where the user might have put my program in ... lets say "c:\xyz\prog.exe"
    that way when i get the directory then i could tell my program to play a music file that came with the program which should be in the same directory n if not then don't play it ...

  7. #7
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    reverse

    If you write and app and don't use app.path
    and for arguments sake we store your files
    in c:\yourfolder
    We then take your app and install it on my pc
    but on my pc I put your app in D:\myfolder

    When I go to run your app I will get errors
    on file not found because the path's will be
    different even though the file names are the
    same.

    If you use app.path then app.path is the path
    the app is stored in so regardless of where it
    is stored it will look for yourfile.txt and
    find it as long as it is stored in the folder
    where your app is stored.

    When I dim AppPath I am just creating
    an instance of App.Path and if the App.Path
    doesn't have a \ on the end of it I am putting
    one there. I then use AppPath instead of App.Path
    Just habit..you could just as easily just add
    the \ to the end of App.Path if it wasn't there

    That is the best I can do at explaining the function
    App.Path
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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