Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004
    Posts
    173

    Unanswered: Editing a Text File

    I've got a CSV that I need to edit before I import it. The file has two lines at the top that I need to delete unless I want to go through it line by line myself. I'm wondering the best way to do this - my thinking is that I open the file in question and read it into a new file after skipping the first two lines. Would this be the correct and or the easiest way to do this? Any help appreciated. Thanks in advance.

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    That's the way I do it - every day to about a dozen files. Never have any problems with it.
    Inspiration Through Fermentation

  3. #3
    Join Date
    Apr 2004
    Posts
    173
    Thanks, and this is the way I did it. Any improvements appreciated.

    Private Sub fixTextFile(strPath As String)
    Dim oFs As New Scripting.FileSystemObject
    Dim oTxtRead As TextStream, oTxtWrite As TextStream
    Dim strWritePath As String

    strWritePath = "C:\TEMP\Order_DB_temp_txtFile.csv"
    Set oTxtRead = oFs.OpenTextFile(strPath, ForReading)
    Set oTxtWrite = oFs.CreateTextFile(strWritePath)
    oTxtRead.SkipLine
    oTxtRead.SkipLine
    Do While Not oTxtRead.AtEndOfStream
    oTxtWrite.WriteLine (oTxtRead.ReadLine)
    Loop
    oTxtWrite.Close
    oTxtRead.Close

    importTxtFile (strWritePath)
    oFs.DeleteFile (strWritePath)
    End Sub

Posting Permissions

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