Append to beginning of text file instead of bottom using .vbs

Posted on 2009-04-20
Last Modified: 2013-12-26
I'm trying to append to the top of a text file rather then the bottom. How can I do this?
This code writes to the bottom rather then the top.

Set objFile1 = objFSO.OpenTextFile("C:\offline.txt", 8)

objFile1.Write VbCrLf & strcomputer

Open in new window

Question by:Darkejo1
    LVL 92

    Accepted Solution

    Dim objFSO, objFileIn, objFileOut, Content

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFileIn = objFSO.OpenTextFile("C:\offline.txt")
    Content = objFileIn.ReadAll
    Set objFileOut = objFSO.CreateTextFile("C:\offline.txt", True)
    With objFileOut
        .WriteLine vbCrLf & strcomputer
        .Write Content
    End With

    Set objFileIn = Nothing
    Set objFileOut = Nothing
    Set objFSO = Nothing

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    758 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

    11 Experts available now in Live!

    Get 1:1 Help Now