Hello!
I'm fairly new to scripting and was looking at setting up my first file monitor. Basically we have a file that is put on a server every day. If the file is not there by 12:30pm each day, we need to be notified.
Can the team help be out? I was looking at the File Count Script but I have no idea how or where to edit it. I also do not know what to use for the Script Arguments either. Here is the script I was thinking of using:
Maybe highlight in RED what needs to be changed, and I can take it from there. Also need to know what the argument should be.
Option Explicit
On Error Resume Next
Const FAIL = 1, SUCCESS = 0
Dim lstArgs, path, extension, oRegEx, fso, objDir, objFiles, fileName, matches
Set lstArgs = WScript.Arguments
If lstArgs.Count = 2 Then
path = Trim( lstArgs( 0 ))
extension = Trim( lstArgs( 1 ))
Else
WScript.Echo "Message: Usage: cscript.exe FileCount.vbs [pathToFiles] [extension]" _
&vbCRLF &" [pathToFiles] Local or UNC Path "_
&vbCRLF &" [extension] File Extension (no ""."" required )"
WScript.Echo "Statistic: 0"
WScript.Quit( FAIL )
End If
Set oRegEx = New RegExp
oRegEx.Pattern = "\."
oRegEx.Global = True
oRegEx.IgnoreCase = True
' Remove all '.' characters from extension string
extension = oRegEx.Replace( extension, "" )
If( Len( extension ) = 0 )Then
WScript.Echo "Message: Invalid Extension."
WScript.Echo "Statistic: 0"
WScript.Quit( FAIL )
End If
Set fso = Wscript.CreateObject( "Scripting.FileSystemObject" )
If fso.FolderExists( path ) Then
Set objDir = fso.GetFolder( path )
If( IsEmpty( objDir ) = True ) Then
WScript.Echo "Message: Object (Directory) not initialized"
WScript.Echo "Statistic: 0"
WScript.Quit( FAIL )
End If
Set objFiles = objDir.Files
If( IsEmpty( objFiles ) = True ) Then
WScript.Echo "Message: Object (Files) not initialized."
WScript.Echo "Statistic: 0"
WScript.Quit( FAIL )
End If
matches = 0
For Each fileName In objFiles
If InStrRev( LCase( fileName ), LCase( "." & extension ) ) = ( Len( fileName ) - Len( "." & extension ) + 1 ) Then
matches = matches + 1
End If
Next
Else
WScript.Echo "Message: Folder not found."
WScript.Quit( FAIL )
End If
WScript.Echo "Message: "& CInt( matches ) & " matches found."
WScript.Echo "Statistic: " & CInt( matches )
WScript.Quit( Success )