Results 1 to 4 of 4

Thread: Clearing Out a Text File

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Posts
    30

    Clearing Out a Text File

    Hello again! I've got a question which I think is probably pretty simple. I've got a text file called "prefs.ini." I just need to clear its contents. I think it contains 6 lines or so, and I just want to clear 'em all out. Here's my code:

    Private Sub clearfile(ByVal location)
    Dim writer As StreamWriter = New StreamWriter(location)

    'I want to clear all contents of this file

    End Sub


    Thanks!
    Sincerely,
    Reid V. Plumbo
    [email protected]

  2. #2
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    I guess the easiest way would be to just ooen it with a filemode of create

    For example.
    VB Code:
    1. Dim objWriter As New _
    2.           IO.FileStream("c:\Test.txt", _
    3.           IO.FileMode.Create, _
    4.           IO.FileAccess.Write)
    5.       objWriter.Close()

  3. #3
    Junior Member
    Join Date
    Sep 2001
    Location
    Australia
    Posts
    30
    Just out of curiosity. Wouldn't it be easier to delete the file and then recreate it later (in code where you need it)?
    <! Ozki !>

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Posts
    30
    Yup. That's what I eventually did. I used Kill("myfile.ini") and that did the trick.

    Reid

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