Append Entire File Content to Another File

  • Hello,Does anyone have an example as to how I could take the entire contents of one text file, and append those contents to the content of another text file? 
    Is there some way to use the WriteLine method (VBScript FileSystemObject) to do this?
    Thank you for your help!CSDunn
  • set fso=createobject("scripting.filesystemobject")

    set nfl = fso.createtextfile("c:\pathtoresultfile\resultfile.txt")

    set fl= fso.OpenTextFile("c:\pathtofile1\file1.txt")

    do while not fl.atendofstream

     nfl.writeline fl.readline

    loop

    set fl= fso.OpenTextFile("c:\pathtofile1\file2.txt")

    do while not fl.atendofstream

     nfl.writeline fl.readline

    loop

    set fl= fso.OpenTextFile("c:\pathtofile1\file3.txt")

    do while not fl.atendofstream

     nfl.writeline fl.readline

    loop

    nfl.close

    set nfl=nothing


  • Thanks for your help, I'll try this!

    CSDunn

  • It could also be done using xp_cmdshell and the TYPE command, thus:

    EXEC master.dbo.xp_cmdShell 'TYPE C:\TextFile.txt >> C:\TextFile2.txt'

    This would append the contents of Textfile.txt to TextFile2.txt on the SQL server. You can also use computer name (\\COMPUTER\...) paths for files over the network using this method.

     



    Ade

    A Freudian Slip is when you say one thing and mean your mother.
    For detail-enriched answers, ask detail-enriched questions...[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply