How can I be notified if a single file exceeds a certain file size?

Article ID: 207
Category: Scripts
Applies to: All Versions
Updated: 2019-07-25

You can launch the following VBScript through the application scheduler (e.g. every 1 minute) to be notified when the size of a file exceeds a configurable limit.

Note: The file needs to be saved with the .vbs extension and called it through cscript.exe.

You can configure the file with the FILE_NAME variable, and the maximum size of the file with the MAX_FILESIZE_IN_BYTES variable. Please note that the file size needs to be specified in bytes.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
' Checks the size of a single file
'  
' Returns 0 if the file size is below the max size, or returns 1 
' if the size exceeds the max size. Check return code through %ERRORLEVEL%.

Option Explicit

Dim exitCode : exitCode = 0
Dim objFSO, objFile

' Set your values here
Const FILE_NAME = "C:\logs\cc.log"
Const MAX_FILESIZE_IN_BYTES = 10485760   ' 10 Mb

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(FILE_NAME)

If objFile.Size > MAX_FILESIZE_IN_BYTES Then 
    exitCode = 1
End If

Wscript.Quit exitCode


Try EventSentry on-premise

FREE 30-day evaluation

Download Now