VBScript Function to process file in -> file out
Posted on 2008-06-11
I need a function in VBScript that accepts 3 parameters, an input filename, an output filename and a string.
I want the function to open the input file for reading and the output file for appending.
I want to write each line of the input file to the output file with the string prepended to the data, then close the files and return the number of lines written (or read)
Here is an example:
calling the function:
lc = WriteOutput("c:\mydata\myfilein.txt", "c:\mydata\myfileout.txt", "123456,")
MsgBox cstr(lc) & " lines written"
If the contents of c:\mydata\myfilein.txt was:
the file c:\mydata\myfileout.txt would contain (after the call):
IMPORTANT: If c:\mydata\myfileout.txt already contains data, I want the additional data appended to the file. Thus, if I called the function a second time, with a different input filename and string but same output file, the contents of the string + input file would be added to the output file.