WatchDirectory Forum
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl
watchDirectory forums >> How to... >> Filter by file size?
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl?num=1504698276

Message started by Rawson819 on Sep 6th, 2017 at 1:44pm

Title: Filter by file size?
Post by Rawson819 on Sep 6th, 2017 at 1:44pm
Is there a way in WD that I can filter by file size?  I have a daily report that I've been emailing to staff using WD.  It worked perfectly until the originating software started creating the report in triplicate, with two of the files being nearly blank, except column headers.

Until the triple report problem can be solved, I was wondering if I could have WD ignore files that are 6KB or less. I would also add that there is never any consistency to the order in which the three files appear.  On days when the first file is the one with data, things are great; however, when not, a blank report goes out.  I'm open to any suggestions, if there is perhaps another way around the issue.  Thanks,

Title: Re: Filter by file size?
Post by Gert on Sep 7th, 2017 at 6:33am
Hi,

Make sure you run the latest version of WatchDirectory. Change the task settings as follows:
Change the "Monitoring Method" to either "Polling" or (better) "File Age" and set the "age" to 1 minute, also let it "remember triggered files".
At the bottom of "Filter Events" add a filter script, for example C:\Scripts\filter6kb.bat. This script should look like this:
[code]rem ignore all files smaller than 6kb

rem file does not exist... we are probably called by the Control Center to test
rem just tell WD to ignore this event.
IF NOT EXIST "%WD_FILE%" GOTO :SayNo

IF %WD_FILE_SIZE_KB% LEQ 6 GOTO :SayNo

rem file is bigger than 6kb
GOTO :SayYes

:SayYes
ECHO Y > "%WD_FILTERRESULT%"
GOTO :EOF

:SayNo
ECHO N > "%WD_FILTERRESULT%"
GOTO :EOF
[/code]



The reason why you can not use the "Default" or "Fast" monitoring method is that those methods may detect the file to quickly. All files always start their life as zero-byte files (even if just for a few milliseconds) so "Fast" could call your filter script too soon.

WatchDirectory Forum » Powered by YaBB 2.5.2!
YaBB Forum Software © 2000-2017. All Rights Reserved.