VBScript to read and write the data in a text file
kw.vbs
Set objFSO = CreateObject("Scripting.FileSystemObject")
filePath = "D:\VBScript\Trial.txt"

Set objFile = objFSO.OpenTextFile(filePath, 8) '8 for appending text
objFile.Write "I am " & vbCrLf & "Writing"
objFile.Close

If objFSO.GetFile(filePath).Size > 1 Then
    Set objFile = objFSO.OpenTextFile(filePath, 1) '1 for reading text
    Do Until objFile.AtEndOfStream 
        strLine = objFile.ReadLine
        print strLine
    Loop
    objFile.Close
Else
    print objFSO.GetFileName(filePath) & " File is Empty"
End If
Output

Advertisement