WatchDirectory home page
WatchDirectory Startseite (Deutsche Version)
Site WatchDirectory (Français)
  Welcome, Guest. Please Login or Register
YaBB - Yet another Bulletin Board
   
  HomeHelpSearchLoginRegister  
 
Page Index Toggle Pages: 1
Monitor a Floder for a File Count (Read 2234 times)
rhayden
YaBB Newbies
*
Offline



Posts: 6
US, Maryland
Monitor a Floder for a File Count
Jul 31st, 2006 at 4:15pm
 
Hello, I would like to monitor a folder for a file count.  If the folder contained, say,  over 100 files I would like to be notified of that fact.  Any thoughts on how I could do this with watchDirectory?
Rich
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2225
The Netherlands
Re: Monitor a Floder for a File Count
Reply #1 - Jul 31st, 2006 at 6:51pm
 
Hello Rich,

If you use the [url=www.watchdirectory.net/wdhelp/plugins/wdopAutoRunBat.html]batch script plugin[/url] and let it monitor the folder for new files it should be possible. Use the script below (name it CheckDirectory.bat for example), but be sure to change the email address (it now sends to John Doe).

See [url=www.watchdirectory.net/wdhelp/plugins/wdopAutoRunBatEmail.html]sending email from batch scripts[/url] for more help on sending mail.

Note that this script only counts files inside the directory itself, not inside sub-directories.

[code]
rem immediately quit if not called for a new file
IF "%WD_REASON%" NEQ "FILENEW" GOTO :EOF

rem the number of files to allow inside the directory
SET MAXALLOWED=100

rem count the number of files in the directory that is monitored
SET CNT=0
FOR %%C IN ("%WD_FILE_D%*.*") DO (
     Call :AddOne
)
If %CNT% LEQ %MAXFILESALLOWED% GOTO :QUIT

set EMAILFILE=%WD_TASKDIR%\..\System.Mail\Out\%WD_CONFIG%_%WD_CUREVT%.TMP
echo %WD_FILE_D%: more than %MAXFILESALLOWED% files > "%EMAILFILE%"
echo John Doe^<j.doe@johndoe.com^> >> "%EMAILFILE%"
echo. >> "%EMAILFILE%"
echo. >> "%EMAILFILE%"
echo. >> "%EMAILFILE%"
echo pecunia non olet >> "%EMAILFILE%"
echo Hi, >> "%EMAILFILE%"
echo There are currently %CNT% files >> "%EMAILFILE%"
echo in directory %WD_FILE_D% on computer %COMPUTERNAME% >> "%EMAILFILE%"
rem okay, the script is created, now rename it so the wdPostMan program processes it.
ren "%EMAILFILE%" %WD_CONFIG%_%WD_CUREVT%.wdmail

GOTO :QUIT

GOTO :EOF
:AddOne
SET /a CNT=%CNT% + 1
GOTO :EOF

:QUIT
[/code]
Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
Page Index Toggle Pages: 1