Cari Blog Ini

19 Juni 2012

How To Copy File .txt to New File Using VB Script

1. Prepare a sample file, example : "TestRead.txt"





2. Copy this code, in new file :
'--------------------------------------------------------------
'-----code:start
'--------------------------------------------------------------
Dim arrFileLines()
i = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("TestRead.txt", 1)
Set objoutputFile = objFSO.CreateTextFile("TestResult.txt")

Do Until objFile.AtEndOfStream
    Redim Preserve arrFileLines(i)
    arrFileLines(i) = objFile.ReadLine
    i = i + 1
Loop

objFile.Close

For l = 1 to i-1
    objoutputFile.writeline arrFileLines(l)
Next

objoutputFile.close
--------------------------------------------------------------
'-----code:end
'--------------------------------------------------------------


3. Save file in the point "2.", example : "ReadTextFile.vbs"




4. Then double-click the file name ""ReadTextFile.vbs"

5. Will results below: