cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 10

Monitoring number of files in a folder with a specific name scheme.

Is there a way to monitor the number of files in a folder that start with a specific file name?

I have a request to monitor a folder and look for the number of files that start with Order then the date, so this folder could look like:

Order11282011.txt

Order11292011.txt

Order11302011.txt

Invoice11282011.txt

Invoice11292011.txt

Error11302011.txt

Normally the File Count would work great, but for the purpose of this monitoring check I only care about the files named Orderxxxxxxxx.txt and not Invoice or Error.  We want to be able to track when Order files are placed into this folder and when they are moved out of the folder when they are processed.  Being able to get the number of files as a statistic would be helpful, since if they exceed a certain amount it could also tell us that the transfer process is not working or falling behind.

I am still stuck on APM 3.5 sadly so if there is a custom script it would have to be VBScript.

Thanks.

0 Kudos
2 Replies
MVP
MVP

VBScript isn't normally my thing, but I was able to google enough to throw this together for you.  Change the srcDirectory to suit your purpose.

Update: Looking at the comments by aLTeReGo on this thread, it looks as though the code below may need some love if you're going to access a network path.

'

' Script : count-orders.vbs

' Purpose: Count number of order files in the source path and

'          report that as the statistic for SAM.

'

' Author : Steven "MrXinu" Klassen <sklassen@sigmasolinc.com>

'

'===========================================================================

Option Explicit

Dim fso, count, srcDirectory, folder, file

Set fso = CreateObject("Scripting.FileSystemObject")

srcDirectory = "C:\Your\Path\Here"

Set folder = fso.GetFolder(srcDirectory)

count = 0

For Each file in folder.files

    If Left(fso.GetFileName(file), 5) = "Order" Then

        count = count + 1

    End If

Next

WScript.Echo "Statistic: " & count

WScript.Quit(0)

0 Kudos
Product Manager
Product Manager

The File Count Monitor in SAM v5.0 does not currently support filtering by file name, only by extension. I've logged this as a feature request under FB160993.

0 Kudos