Read and write into a DB text file

Posted on 2006-05-02
Last Modified: 2006-11-18
I have two text files text1.txt and text2.dat
Text1.txt contains data which i would like to manipulate and then write the modifications to text2.dat

How do I read line for line in text1.txt modify the string and than write it line for line to text2.dat? Do not worry about the the modification bit, I know how to do that. I am only interested in the reading and wrting part.

Question by:LotharGores
    LVL 28

    Accepted Solution

    Set oFS = Server.CreateObject("Scripting.FileSystemObject")
    Set oReadFile = oFS.OpenTextFile("C:\temp\readfile.txt")
    Set oWriteFile = oFs.OpenTextFile("C:\temp\writefile.txt",8)
    Do While Not oReadFile.AtEndOfStream
        sLine = oReadFile.ReadLine
    oReadFile.Close: Set oReadFile = Nothing
    oWriteFile.Close: Set oWriteFile = Nothing
    Set oFs = Nothing
    LVL 2

    Author Comment

    Hi sybe,
    can you provide me with some code to check "writefile.txt" exists - and if not to create it!

    thanks for the above code works just fine!
    LVL 28

    Expert Comment

    Set oFS = Server.CreateObject("Scripting.FileSystemObject")
    Set oReadFile = oFS.OpenTextFile("C:\temp\readfile.txt")
    If Not oFS.FileExists("C:\temp\writefile.txt") Then oFs.CreateTextFile("C:\temp\writefile.txt")
    Set oWriteFile = oFs.OpenTextFile("C:\temp\writefile.txt",8)


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
    Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now