Folder Monitoring question?

Does anyone know of a good way to monitor a folder for file number of files it contains?  I have a server that I need to watch a certain folder that if the number of files in it exceeds a certain number, I'll get an email.  I don't care about file types, I just need to be alerted if the number of files in this server exceeds a certain threshold.  I've tried automate to do it, but that didn't work out to well.  Does anyone have a better way or know of a good software package that would do it?  Hopefully free!

thanks
LVL 9
MCPJoeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

woodas26Commented:
Hi MCPJoe.  This software package looks pretty good.  (Not free, though)

http://www.watchdirectory.net/index.html

I'll keep looking and see if I can find a free one.
0
MCPJoeAuthor Commented:
That looks like it will do the job, but I am hoping to find a free way to do it.  Even if its VB or something, I don't need anything fancy, just an email alert based on the number of folder items.  

Thanks
0
TheCleanerCommented:
This script will count the number of files in a given folder and return the value in an email:


Dim objFSO
Set objFSO = CreateObject("Scripting.filesystemObject")

'Get the folder object associated with the directory
Dim objfolder
Set objfolder = objFSO.Getfolder("C:\My Downloads")

'Loop through the files collection
Dim objFile, fileCount
fileCount = 0
For Each objFile In objfolder.files
fileCount = fileCount + 1
Next

Set objEmail = CreateObject("CDO.Message")

objEmail.From = "TheCleaner@test.com"
objEmail.To = "TheCleaner@test.com"
objEmail.Subject = "File count of c:\My Downloads"
objEmail.Textbody = fileCount
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "10.10.10.8"
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send


You will need to change:
C:\my downloads = directory to check
email to and from
smtpserver (your exchange server)

That's it...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

TheCleanerCommented:
oops...forgot you wanted it only if it exceeds...

So you can say right about "set objEmail":

IF fileCount > 30 Then


(then put End IF below the objEmail.Send)
0
TheCleanerCommented:
oops again...dang it...the "right about" above should be "right above"
0
MCPJoeAuthor Commented:
Is there any special software that needs to be installed for this work?  Could I run this as a ask in task manager?  Also, how does the email sending work, or would it be possible to specify an SMTP server and port with credentials?  I'll give this a try.  

Thanks
0
TheCleanerCommented:
It's simple vbscript.  save it as a .vbs file.  You can run it as a task in task manager at specified times as needed.

The email sending works using Collaboration Data Objects, built into the OS, no software required.  All that is needed is to have access to the SMTP server in your organization.  No credentials are required.
0
MCPJoeAuthor Commented:
Usually no credentials are required, but I don't have access to any unsecured SMTP servers.  I need to be able to specify credentials to authenticate to an SMTP server.  Is there any way to do that?  Otherwise I think the script is working, the only errors I get are with connecting to an SMTP server.

Thanks
0
MCPJoeAuthor Commented:
Also, is there a way to customize the body of the message to add more text than just the file count?  I tried to add a quoted text but I get an error when running the script.
0
TheCleanerCommented:
What kind of SMTP server do you have?  What's the exact error you get?

Yes, you can add text to the body...it would be in the following fashion:

objEmail.Textbody = "Total number of files in the folder = " & fileCount
0
MCPJoeAuthor Commented:
Thanks so much, that works perfectly.  This is exactly what I was looking for.  

Thanks again
0
TheCleanerCommented:
Very welcome...

For future reference, this part in the script:

Set objEmail = CreateObject("CDO.Message")

objEmail.From = "TheCleaner@test.com"
objEmail.To = "TheCleaner@test.com"
objEmail.Subject = "File count of c:\My Downloads"
objEmail.Textbody = fileCount
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "10.10.10.8"
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send


Can be used in any vbscript (basically just changing the from, to, subject, and textbody).  So keep that part handy to add to other scripts you need to get emails from.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.