Results 1 to 4 of 4

Thread: Open a file in the current directory

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224

    Question

    Hi guys
    I'm just wondering can anyone tell me how to open a file in a current directory,
    eg,
    code/
    [Open "Current Directory\text.txt for Append as #1. ]

    I'm creating a file and I want it to be created in the same directory that as the application is run from. I heard something about "cardir", but I'm not to sure, Can anyone help???



    [Edited by kanejone on 08-25-2000 at 10:18 AM]

  2. #2
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    app.path+"\filename.txt"
    Kurt Simons
    [I know I'm a hack but my clients don't!]

  3. #3
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    That's not CarDir, it's CurDir.
    First:
    Code:
    Function AddSlash(ByVal sPath As String) As String
        AddSlash = sPath & IIf(Right(sPath, 1) = "\", vbNullString, "\")
    End Function
    Then:
    Code:
    ' If you want to open the file from the CURRENT directory:
    Open AddSlash(CurDir) & "text.txt" For Append As #1
    ' If you want to open the file from the APPLICATION'S directory:
    Open AddSlash(App.Path) & "text.txt" For Append As #1

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    Thanks a lot
    That was exactly what I needed,
    Take care
    JK

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