A couple of examples merging two files together.
Example 1: - The long way
// Create FileSystemObject - Needed for working with files
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
// Open files
var f1 = fso.OpenTextFile( "firstfile.txt", 1 ); // Open for reading
var f2 = fso.OpenTextFile( "secondfile.txt", 1 ); // Open for reading
var f3 = fso.OpenTextFile( "Output.txt", 2, true ); // Open for writing, create
f3.Write( f1.ReadAll() ); // Write Data from first file to output
f3.Write( f2.ReadAll() ); // Write Data from second file to output
// Close files
f1.Close(); f1 = null;
f2.Close(); f2 = null;
f3.Close(); f3 = null;
Example 2: - Shorter and in a function
// Call our function to append the
// 'second' file to the 'first'
append( "first.txt", "second.txt" );
// function to merge two files together
function append( topfile, bottomfile )
{
// Error trapping
try
{
// Create FileSystemObject
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
// Open file for appending, don't create
var ftop = fso.OpenTextFile( topfile, 8, false );
// Open for reading
var fbot = fso.OpenTextFile( bottomfile, 1 );
// Append the contents of second file to first
ftop.Write( fbot.ReadAll() );
}
catch( e )
{
// Display any errors
WScript.Echo( "Error: " + e.description );
}
}