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

Thread: App.Path issue

  1. #1
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    App.Path issue

    What is the difference if I execute App.Path & "\File.txt" or just "File.txt". I mean what's the use of App.Path anyway if the default path is App.Path when working with files?

  2. #2
    Join Date
    Feb 2002
    Location
    Makati City, Philippines
    Posts
    1,054
    "App.Path" is an insurance that you're referrring to your application's path for files. I have observed in the past that when I frequently use ChDir in my applications, the "defaut" path can "go wild."

    Sorry, it was just an observation which I did not verify very well because "App.Path" can easily put me back in the right track.
    Marketing our skills - please participate in the survey and share your insights
    -

  3. #3
    Join Date
    Sep 2001
    Location
    IL, USA
    Posts
    1,090
    'Add to a form a Commondialog box and a commandbutton. Compile project and make an executable.
    'Add a file called Myfile.txt to the folder with the just created executable.
    Code:
    Option Explicit
    'In principal if the current directory, which is by default is the same as the app.path, did not
    'change through the whole application then you don't need the app.path.  But if the current directory changes then
    'you start getting problems.  Below there are two cases where the current directory changes and you get the wrong path.
    Private Sub Command1_Click()
       'By default the current directory is the app.path
       MsgBox "File:" & Dir("Myfile.txt") & "  Current dir: " & CurDir
       'If you select a file from another directory the you changed the current directory
       'So in principal Myfile.txt Dir("Myfile.txt") should be empty
       CommonDialog1.ShowOpen
       MsgBox "File:" & Dir("Myfile.txt") & "  Current dir: " & CurDir
       'Similarly if you change the current directory using ChDir then
       'Dir("Myfile.txt") will probably be empty
       ChDir "c:\"
       MsgBox "File:" & Dir("Myfile.txt") & "  Current dir: " & CurDir
    End Sub

  4. #4
    Join Date
    Jun 2002
    Location
    Finland
    Posts
    57
    With Flags property you can control behavior of CommonDialog

    That code does not change programs CurDir
    CommonDialog1.Flags = CommonDialog1.Flags Xor cdlOFNNoChangeDir

    That code change programs CurDir
    CommonDialog1.Flags = CommonDialog1.Flags or cdlOFNNoChangeDir

  5. #5
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080
    Sometimes, the App.path is different from the path where the environment runs it ( Check shortcut for example ).

    The app.path refers to where the EXE file is. but it could run in another directory. So if you just specify text.txt it checks on the current working directory which might be different from where the applications resides.
    Nicolas Bohemier

  6. #6
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817
    Hi,
    so pretty much App.Path is required? How come when App.Path is c:\ or c:\folder it still work using App.Path & "\file.txt"??? I mean if App.Path is c:\ then App.Path & "\file.txt" would be c:\\file.txt. I tried both and it still works. Do i have to create a control code something like
    Code:
    If Right(App.Path, 1) = "\" Then
    ProgPath = Left(App.Path, Len(App.Path) - 1)
    Else: ProgPath = App.Path
    End If
    to make sure it works or it'll work anyway?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)