I'm reading a list of printers into a dic array and using the printer name as a variable to parse out the same name from a series of txt files. For each instance of a unique printer name, I want the script to either create a new file with the printer name or append to a file if one already exists and write out the username, computername, and whether the printer is default or not.
The problem I'm having is the script is reading through the files however, it's not starting over with each new printer variable. Also, the printer names aren't going into the correct printer files.
Could someone help me figure out why the script is behaving this way please?
The problem I'm having is the script is reading through the files however, it's not starting over with each new printer variable. Also, the printer names aren't going into the correct printer files.
Could someone help me figure out why the script is behaving this way please?
Code:
'Option Explicit
'On Error Resume Next
Dim objFSO, objFolder, objFile, testFile, varLine, objTextFile, objDictionary
Dim strNextLine, objItem, Printer, objTS, RepDirectory
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const SPrinterList = "c:\Printers\printers.txt"
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Open printer list
Set objTextFile = objFSO.OpenTextFile(sPrinterList, ForReading)
i = 0
'run through text file until all printers are placed in array
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
Loop
For Each objItem In objDictionary
Printer = objDictionary.Item(objItem)
RepDirectory = ("c:\printers\ListPrinters\")
Set objFolder = objFSO.GetFolder("\\fay-insightmgr\listprinters$\")
For Each objfile in objfolder.Files
Set testFile = objFSO.OpenTextFile(objFile.path, ForReading)
Do Until testFile.AtEndOfStream
varLine = testFile.ReadLine
If InStr(1, LCase(varLine), LCase(printer))<> 0 Then
Report = Report & "Computer Name: " & objFile & VbCrLf
Report = Report & "Printer: " & varLine & VbCrLf
If objFSO.FileExists(RepDirectory & Printer & ".txt") Then
Set objTS = objFSO.OpenTextFile(RepDirectory & Printer & ".txt", ForAppending)
Else
Set objTS = objFSO.CreateTextFile(RepDirectory & Printer & ".txt", ForWriting)
objTS.Close
Set objTS = objFSO.OpenTextFile(RepDirectory & Printer & ".txt", ForAppending)
End If
objTS.Write Report
objTS.close
End If
Loop
testfile.close
Next
Next