My VBScript checks if the timestamp of a certain file is older then what has been passed in a argument.
If it is older then the argument allows, then the status of the log file created by this script is set to STATUS="ERROR". When STATUS="ERROR" then the tail of the error log (10 lines of code) is to be written to the Log file. So far, this works.
The problem is now that in the folder, where the scripts is running on, there are more then just .log and .txt files. One can also come across .zip or .rar files.
If one of them throws an error, the script when running tail on it gives the following
œšF§p#ýÃZ§‘KnÄÈÙCÓÈ7Ò-Ã"œs#GNM£S¸‘þaÓÈ%7bäì¡iä‚é–a‘F¯Îüm‹™Êh f"Ò>¨Û%þ#N™«Q,ø Ð}e
·v–‰³‘$j9Õ‡ó–i;!žBÉFëîÑ>
p“Ò(ä3óÍ.x;…&µb6òhj˜æ '½3Izô
ëùÿzjsÁ Æ÷vÌ‚F®Qe{cÍË<‹ù‰É1²F†y¿Ð"ÂÄ8jãVÒ«
this is of course not what I would like to see.
The questions are:
Is there a way to make the script ignore other files extension than .log and .txt files and then just when the file extension is something else just inserts a string message?
Is there a way to make the script open the .zip and .rar file take the newest file inside and run the tail.exe file on this file?
if(status = "ERROR") then
'Runs the tail.exe file to get the last 10 lines of text in the [sNewestFile] and insert them to the log file.
'This will only be done IF there is a status = "ERROR"
errorStr = WScript.CreateObject("WScript.Shell").Exec( _
"tail -n 10 """ & sNewestFile & """" _
).StdOut.ReadAll
objLogFile.writeline "" & vbCrLf
objLogFile.writeline "Error Message Start" & vbCrLf
objLogFile.writeline "" & errorStr & vbCrLf
objLogFile.writeline "Error Message End"
End if
Notes:
- I got help in here for that solution: https://stackoverflow.com/a/32352356/3430698
- The two variable are
sNewestFileandsOldestFilethat contains the newest and oldest file. They contain the entire path to the files with extensionsNewestFile = oFile.Path I have a
filespecvariable that is passed in as a argument that is the file extension. So I have tried to run a if sentence around that code above that checks if the status="ERROR", the if sentence was to checkif (filespec <> ".txt" or file <> ".log") then writeline "something" else 'run the tail on the file
filespecvariable that is passed in as a argument that is the file extension. So I have tried to run a if sentence around that code above that checks if the status="ERROR", the if sentence was to checkif(filespec <> ".txt" or file <> ".log" then writeline "something" else 'run the tail on the file