This is the current VB script, you can see the number of IF clauses in the middle, Im looking to plug a further one in. The script goes on to create events within product called MOM. Any help much appreciated!:
'
' Set these values as required
'
Const FOLDER_NAME = "c:\testfolder"
Const DELETE_ZERO_BYTE_FILES = False ' *** True = delete the zero-byte files, False = report only
Const FILE_CREATE_DELAY_SECONDS = 30 ' *** Only check files older than this time
'
' Script constants
'
Const ARCHIVE_BIT = 32
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_INFO = 2
Dim fso
'
' Start of script
'
Set fso = CreateObject("Scripting.FileSystemObject")
Call CheckFiles
Set fso = Nothing
' End -----------------------------------------------------------------------------------
Sub CheckFiles()
Dim fsoFile
Dim NumberOfFiles : NumberOfFiles = 0
Dim FoundFiles : FoundFiles = ""
'
' Check that the folder we are going to examine actually exists, otherwise raise an
' alert and exit.
'
If fso.FolderExists(FOLDER_NAME) = False Then
Call CreateMomEvent(997, EVENT_TYPE_ERROR, "The specified folder for zero-byte file detection was not found.")
Exit Sub
End If
'
' Iterate through the collection of files in our folder
'
For Each fsoFile In fso.GetFolder(FOLDER_NAME).Files
'
' Files are created with the Archive bit set by default. Check if the Archive bit
' is set - if not then this we are not interested. As we process each zero-byte file
' we will clear the Archive bit so that it will not be processed again.
'
If ((fsoFile.Attributes And ARCHIVE_BIT) = ARCHIVE_BIT) Or (DELETE_ZERO_BYTE_FILES = True) Then
'
' We have a file with the archive bit set meaning that either it is a new file or
' was checked previously but was not zero-bytes in length.
'
' If the file was created less than FILE_CREATE_DELAY_SECONDS ago then we will ignore
' it as it may be zero length simply because the creating process hasn't written to it
' yet - e.g. file writes may be buffered.
'
If DateDiff("s", fsoFile.DateCreated, Now) > FILE_CREATE_DELAY_SECONDS Then
'
' The file was created greater than FILE_CREATE_DELAY_SECONDS ago so check
' if its size is zero bytes in length.
'
If fsoFile.Size = 0 Then
FoundFiles = FoundFiles & fsoFile.Name & ", "
'
' The file is zero bytes in length - increment our counter and reset the
' file's Archive bit so that we'll know in future its been processed.
'
NumberOfFiles = NumberOfFiles + 1
fsoFile.Attributes = fsoFile.Attributes Xor ARCHIVE_BIT
If DELETE_ZERO_BYTE_FILES = True Then
On Error Resume Next
Call fsoFile.Delete(False)
If Err.number <> 0 Then
Call CreateMomEvent(996, EVENT_TYPE_ERROR, "Failed to delete zero-byte file '" & fsoFile.Name & "'. " & Err.Description)
End If
On Error GoTo 0
End If
End If
End If
End If
Next