I'm trying to run a script that checks various log files with filenames in them to see if they exist or not and then writes results to a log file. So, I've used the fso.opentextfile to first open up a report of each of the log files in the main directory, then fso.opentextfile again to open up each individual log file to check and see if the files exists.
Checking a single log at a time with seperate scripts works perfectly. However, trying to automate this so that it switches between all the logs and keeps running gives me the following error:
Windows Script Host
Script: C:\Documents and Settings\desktop\testfilesearch-update.vbs
Line: 14
Char: 1
Error: File not found
Code: 800A0035
Source: Microsoft VBScript runtime error
I checked and made sure that everything exists, and it does, but I'll be darned if I can figure out why it errors out. Please help, my eyes hurt, lol.
Checking a single log at a time with seperate scripts works perfectly. However, trying to automate this so that it switches between all the logs and keeps running gives me the following error:
Windows Script Host
Script: C:\Documents and Settings\desktop\testfilesearch-update.vbs
Line: 14
Char: 1
Error: File not found
Code: 800A0035
Source: Microsoft VBScript runtime error
I checked and made sure that everything exists, and it does, but I'll be darned if I can figure out why it errors out. Please help, my eyes hurt, lol.
Code:
Dim fso, logFileName, logFile, f, Msg, startFolder, lookingfor, count, l, reqlogs
logFileName = "C:\Documents and Settings\Desktop\J3715168r_0604251600" & ".out"
Set fso = CreateObject("Scripting.FileSystemObject")
Set logFile = fso.CreateTextFile(logFileName, True)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set l = fso.OpenTextFile("C:\soundservant\ftp\currentreqfiles.log", ForReading)
Do Until l.atendofstream = True
reqlogs = l.Readline
Set f = fso.OpenTextFile(reqlogs, ForReading)
Do While f.atendofstream <> True
ReadTextFileText = f.Readline
filename = right(readtextfiletext,49)
lookingfor = filename
fullid = left(readtextfiletext,16)
studyid = left(readtextfiletext,3)
qidprep = left(fullid,6)
questionid = right(qidprep,3)
sampleid = right(fullid,10)
startFolder = "C:\Documents and Settings\Desktop"
Count = 0
SearchForFiles startFolder, lookingfor, logFile
wscript.echo lookingfor
if count = 0 then
logfile.WriteLine studyid & " " & questionid & " " & sampleid & " " & filename & " " & "-1"
End If
Loop
Loop
Sub SearchForFiles(folderName, lookingfor, fileObject)
Dim folder, file, fileCollection, folderCollection, subFolder
Set folder = fso.GetFolder(folderName)
Set fileCollection = folder.Files
For Each file In fileCollection
If file.name = lookingfor Then
count = 1
fileObject.WriteLine studyid & " " & questionid & " " & sampleid & " " & file.name & " " & file.size
Else
count = count + 0
End If
Next
Set folderCollection = folder.SubFolders
For Each subFolder In folderCollection
SearchForFiles subFolder.Path, lookingfor, logFile
Next
End Sub