Results 1 to 16 of 16

Thread: one directory above app.path (Resolved)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    California, USA
    Posts
    111

    one directory above app.path (Resolved)

    I want to create a file but 1 directory above app.path.

    app.path & ???? & "\test1.txt"

    in unix it would be \.. to go to the above directory
    what does ???? need to be to achieve this
    Last edited by vbuser1; Apr 14th, 2004 at 06:14 PM.

  2. #2
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    You could read the current path and strip out everything after the second \ from the right and then use the remaining path as your string.

  3. #3
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    VB Code:
    1. Dim i As Integer
    2.  
    3. i = InStrRev(App.Path, "\")
    4. MsgBox Left$(App.Path, i)


    Has someone helped you? Then you can Rate their helpful post.

  4. #4
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    vbuser1


    Or


    app.path & "\..\test1.txt"

  5. #5
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    All that does is add \..\test1.txt to the current path, not bring it up a level.

  6. #6
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    OK, then it is

    app.path & "\..\..\test1.txt"

  7. #7
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    All you are doing is adding the string to app.path, it wont use the \.. command like you can at the command prompt, which is really cd.. for Windows.

  8. #8
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782
    Why dont you get App.Path and then remove the name of the folder the application is in ?!
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  9. #9
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    BrianS,

    You are incorect. I use relative paths all the time to get to files. The OS understands this and it does work.

  10. #10
    Member
    Join Date
    Mar 2004
    Posts
    49
    Randem's method works. And it's
    VB Code:
    1. App.Path & "\.."
    to get the parent directory.

    Leecher

  11. #11
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    Then please explain what I'm doing wrong to try his example:

    VB Code:
    1. Option Explicit
    2. Dim path As String
    3.  
    4. Private Sub Form_Load()
    5. MsgBox App.path
    6.  
    7. path = App.path & "\.."
    8.  
    9. End Sub

    ? app.Path
    C:\Program Files\Microsoft Visual Studio\VB98
    ? path
    C:\Program Files\Microsoft Visual Studio\VB98\..

  12. #12
    Member
    Join Date
    Mar 2004
    Posts
    49
    The string will read "C:\1\2\3\.."

    But if you try to create "Test.txt" in "C:\1\2\3\.." it will actually create "C:\1\2\Test.txt".

    Leecher

  13. #13
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by BrianS
    Then please explain what I'm doing wrong to try his example:

    VB Code:
    1. Option Explicit
    2. Dim path As String
    3.  
    4. Private Sub Form_Load()
    5. MsgBox App.path
    6.  
    7. path = App.path & "\.."
    8.  
    9. End Sub

    ? app.Path
    C:\Program Files\Microsoft Visual Studio\VB98
    ? path
    C:\Program Files\Microsoft Visual Studio\VB98\..
    I have to agree with Brian in this case... I get the same results


    Has someone helped you? Then you can Rate their helpful post.

  14. #14
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    manavo11

    You should... You have to create the file or open it. It is not in human format, the OS understands it thought. Use it like this:

    App.Path & "\..\Test.txt"
    Last edited by randem; Apr 9th, 2004 at 04:40 PM.

  15. #15
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    So you're right

    I did :

    VB Code:
    1. Private Sub Form_Load()
    2.     Dim FF As Integer
    3.     FF = FreeFile
    4.     Open App.Path & "\..\Test.txt" For Output As #FF
    5.     Close #FF
    6. End Sub

    and it worked


    Has someone helped you? Then you can Rate their helpful post.

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    California, USA
    Posts
    111

    Resolved

    app.path & "\..\test1.txt"

    does work when creating a file but the path when display to the screen doesn't match. Thank you all.

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