I have coded the following script out in hopes of the script obtaining information from files in a folder, and summarizing them into a newly made file. When I try to run this script, I get Error (code: 800A1A8, line: 53) "Object required: 'objReadFiles'", but when I insert 'objReadFiles' above line 53, I get an error saying "Type mismatch: 'objReadFiles'" (code: 800A000D). The new file also contains no content.
'Create new output file
Set objFile = objFSO.CreateTextFile("M:\vbscripts\folder\TEST RUN\Summary.txt")
'Read through folder
Set objFolder = objFSO.GetFolder("M:\vbscripts\folder\TEST RUN\COMP")
Set colFiles = objFolder.Files
'Get information and write it in file
For Each objFiles in colFiles
strName = objFiles.Name
num = len(strName) - 13
string_part = left(strName, num)
datetime = CDATE(objReadFiles.DateLastModified)
Do While objReadFile.AtEndOfStream <> True
contents = objReadFile.ReadLine
If Not InStr(contents, "INSTALLED SOFTWARE") > 0 AND InStr(contents, " ") > 0 then
objFile.Write string_part & "," & datetime & "," & contents & vbCRLF
End If
Loop
Next
'Write result into new output file
objFile.Write "end of file"
Not sure what I did to fix it, but it seemed to work this morning. Just wanted to share my final script:
Dim objFSO, objFolder, objFile, colFiles
'Format time stamp for YYYYMMDD_HHMM
strDay = Day(now)
If Len(strDay) < 2 Then
strDay = "0" & strDay
End If
strMonth = Month(now)
If Len(strMonth) < 2 Then
strMonth = "0" & strMonth
End If
strYear = Year(now)
strHour = Hour(now)
If Len(strHour) < 2 Then
strHour = "0" & strHour
End If
strMinute = Minute(now)
If Len(strMinute) < 2 Then
strMinute = "0" & strMinute
End If
Formated_Stamp = strYear & strMonth & strDay & "_" & strHour & strMinute
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Rename old file
If objFSO.FileExists ("M:\vbscripts\folder\TEST\summary.txt") Then
objFSO.MoveFile "M:\vbscripts\folder\TEST\summary.txt", "M:\vbscripts\folder\TEST\Old\summary_" & Formated_Stamp & ".txt"
End If
'Read through folder
Set objFolder = objFSO.GetFolder("M:\vbscripts\folder\TEST\COMP")
Set colFiles = objFolder.Files
'Create new output file
Set objFile = objFSO.CreateTextFile("M:\vbscripts\folder\TEST\summary.txt")
'Get information and write it in file
For Each objFiles in colFiles
Set objReadFile = objFSO.OpenTextFile(objFiles)
Do While objReadFile.AtEndOfStream <> True
contents = objReadFile.ReadLine
If Not InStr(contents, "INSTALLED SOFTWARE") > 0 AND InStr(contents, " ") > 0 then
datetime = CDATE(objFiles.DateLastModified)
strName = objFiles.Name
num = len(strName) - 13
string_part = left(strName, num)
objFile.Write string_part & ", " & datetime & ", " & contents & vbCRLF
End If
Loop
Next
objFile.Write "End of file."
Wscript.Echo "File has been created."