VBscript input error at end of file

I have 3 scenarios where they all need to be executed in the correct order multiple times.

  • 1st script - executes the process in the PC list (specified at the input to the text file) depending on whether they are online / offline. It outputs a list of computers that were online and another list of offline
  • 2nd script - gets PC difference from original list and 1st script output to find out which machines started the process from 1st script
  • 3rd script - using differences, updates the input list

Below is the script of the third script. Whenever I run it, it ends up with an "input end of file" error. I've tried several modifications and it always ends.

My idea for the third script is that the Differences.txt output from the second file is the ones that still need to start the process from the first script, so I just delete the original input file and rename it alone to a new output file. However, I must also keep track of the ones that have already been done with the process, so I have to list / add them to another text file.

Thanks in advance for your help.

Option Explicit
Dim objFso
Dim Fso
Dim firstfile,secondfile,file,fileText

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("Machines.ini") Then objFSO.DeleteFile("Machines.ini")

Set Fso = WScript.CreateObject("Scripting.FileSystemObject")
Fso.MoveFile "Differences.txt", "Machines.ini"


Set fso=CreateObject("Scripting.FileSystemObject")
Set file=fso.OpenTextFile(firstfile)
fileText = fileText & file.ReadAll() & vbCrLf

Set file=fso.OpenTextFile(secondfile)
fileText=filetext & file.ReadAll()

set file=fso.CreateTextFile(secondfile,true)
file.Write fileText



source to share

1 answer

You get this error when you call ReadAll

on an empty file. Check the property AtEndOfStream

and only read the content if it is false:

If Not file.AtEndOfStream Then fileText = fileText & file.ReadAll




All Articles