Writing the New File
Now that the strInput variable holds the name of the .vbs file to which I want to add line numbers, I need to open this file and read the contents line by line. To do so, I use the FileSystemObject::OpenTextFile method with the fso variable I created during initialization (the code at callout B in Listing 1). To ensure that the script opens the file in read-only mode, I defined during initialization a constant called ForReading, which I use as the second parameter to the OpenTextFile method. Then, I attach the open file to the filSource variable. Now I need to open a new temporary file that I can write to.
During initialization, I defined the TEMP_FILE constant, whose value is the temporary file's pathname, and the ForWriting constant, whose value lets you write to a file. To open the temporary file, I use the FileSystemObject::OpenTextFile method againthis time using the new filename, the ForWriting constant, and a value of True, which indicates that the file should be overwritten if it already exists. . . .