WatchDirectory Forum
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl
watchDirectory forums >> How to... >> WD mail Notification Task for Folder Monitoring
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl?num=1486991661

Message started by Shota Tadumadze on Feb 13th, 2017 at 2:14pm

Title: WD mail Notification Task for Folder Monitoring
Post by Shota Tadumadze on Feb 13th, 2017 at 2:14pm
I have 1 WD task that copies the files from source folder to destination, every new file is greater with +1 than previous, e.g. test1.txt, test2.txt, test3.txt, I want create mail notification task, that sends alerts if one of the files will be missed, Can I achieve this with WD?

Title: Re: WD mail Notification Task for Folder Monitoring
Post by Gert on Feb 14th, 2017 at 2:12pm
Create the task with the Email plugin, should be easy enough.

The tricky part is you want to ignore file123.txt if file122.txt exists.
You only want to get an email when file123.txt is detected while file122.txt does not exist.

For this you need a "Filter Script" as described here: http://www.watchdirectory.net/wdhelp/help/filter_events.html

I came up with this script (not tested):
[code]rem this script checks if the previous file is present.
rem when file1234.txt is detected, the script checks for file1233.txt

Call :SplitName

SET /A AFTER=%AFTER% - 1

SET FILE2CHK=%WD_FILE_D%\%BEFORE%%AFTER%.%WD_FILE_E%

IF EXIST "%FILE2CHK%" GOTO :PreviousFileExists
GOTO :PreviousFileDoesNotExists


rem splits WD_FILE_B (for example file1234)
rem into "file" and "1234"
:SplitName
SET BEFORE=
SET AFTER=
SET CHK=%WD_FILE_B%
:SplitName_next
IF "%CHK%" EQU "" GOTO :EOF
SET P1=%CHK:~0,1%
SET CHK=%CHK:~1%
IF "%P1%" EQU "0" GOTO :SplitName_foundNum
IF "%P1%" EQU "1" GOTO :SplitName_foundNum
IF "%P1%" EQU "2" GOTO :SplitName_foundNum
IF "%P1%" EQU "3" GOTO :SplitName_foundNum
IF "%P1%" EQU "4" GOTO :SplitName_foundNum
IF "%P1%" EQU "5" GOTO :SplitName_foundNum
IF "%P1%" EQU "6" GOTO :SplitName_foundNum
IF "%P1%" EQU "7" GOTO :SplitName_foundNum
IF "%P1%" EQU "8" GOTO :SplitName_foundNum
IF "%P1%" EQU "9" GOTO :SplitName_foundNum
SET BEFORE=%BEFORE%%P1%
GOTO :SplitName_next
:SplitName_foundNum
SET AFTER=%P1%%CHK%
GOTO :EOF

:PreviousFileDoesNotExists
rem previous does not exist so this event should trigger
ECHO Y>"%WD_FILTERRESULT%"
GOTO :EOF


:PreviousFileExists
rem previous does exist so this event should be ignored
ECHO N>"%WD_FILTERRESULT%"
GOTO :EOF

[/code]

Title: Re: WD mail Notification Task for Folder Monitoring
Post by Shota Tadumadze on Feb 16th, 2017 at 1:19pm
it works, thank you very much, but I have another problem, every file begins with different numbers, e.g. 201702161550_text1.txt   201602161552_text2.txt, and in this scenario  script doesn't work, without this numbers at front works fine, can you include commands in script that doesn't check filenames before this simbol "_"
will be glad if you can help me

Title: Re: WD mail Notification Task for Folder Monitoring
Post by Gert on Feb 17th, 2017 at 12:55pm
I just corrected an error in the script...

Your new question is for a different file-name scheme...
Are all files named like
99999_AAAA.txt
some numbers, kind of timestamp, followed by an underscore, followed by something else?

Title: Re: WD mail Notification Task for Folder Monitoring
Post by Shota Tadumadze on Feb 20th, 2017 at 10:19am
yes it's timestamp, in this format year,month,day,hour,min_filename
every full filename looks like this
201702201253_b00432841.txt
201702201255_b00432842.txt
201702201257_b00432843.txt

Title: Re: WD mail Notification Task for Folder Monitoring
Post by Shota Tadumadze on Mar 10th, 2017 at 2:26pm
Can you help me with this?

Title: Re: WD mail Notification Task for Folder Monitoring
Post by Gert on Mar 11th, 2017 at 6:22am
Sure. One question, it is not 100% clear to me.
When the file 201702201255_b00432842.txt is detected...
What is the previous file to check for?
should it check for 201702201254_b00432842.txt
or should it check for 201702201255_b00432841.txt

Title: Re: WD mail Notification Task for Folder Monitoring
Post by Shota Tadumadze on Mar 13th, 2017 at 8:49am
the second one, it should check for 201702201255_b00432841.txt

Title: Re: WD mail Notification Task for Folder Monitoring
Post by Gert on Mar 13th, 2017 at 12:03pm
I run into a few problems while testing, please answer...

201702201255_b00432842.txt

The numeric part after "_b", in this case 00432842
Is it always 8 positions/numbers?
Is it always "_b"?
or is it always "_" followed by ONE character-to-ignore, followed by the "sequence number"?

Title: Re: WD mail Notification Task for Folder Monitoring
Post by Shota Tadumadze on Mar 13th, 2017 at 12:45pm
yes, it's always 8 positions/numbers and it's always  "_b"
if it's not yet clear to you every filename looks like this, in this format: year,month,day,hour,min_filename, e.g. for today:
201703131430_b00585555
201703131431_b00585556
201703131433_b00585557
tomorrow it will be like this:
201703141433_b00585558
201703141435_b00585559
every new file appears approximately once in 2-3 minutes

Title: Re: WD mail Notification Task for Folder Monitoring
Post by Gert on Mar 14th, 2017 at 6:59am
Try this script:
[code]rem this script checks if the previous file is present.
rem when 201702201255_b00432842.txt is detected, the script checks for *_b00432841.txt

rem get the last 8 characters from the file title (00432842)
SET SQNUM=%WD_FILE_B:~-8%

rem we can not do arithmetic with numbers having leading zeroes (bat processor assumes it is an octal number)
rem remove the leading zeroes (432842)
Call :RemoveLeadingZeroes

rem get the previous sequence number (432841)
SET /A PRVSQNUM=%SQNUM% - 1

rem add the leading zeroes again (0000000000432841)
SET PRVSQNUM=00000000%PRVSQNUM%

rem it should be 8 digits (00432841)
SET PRVSQNUM=%PRVSQNUM:~-8%

rem the file to check for (C:\MonitorMe\*_b00432841.txt)
SET FILE2CHK=%WD_FILE_D%\*_b%PRVSQNUM%.%WD_FILE_E%

rem and check if a matching file is found
DIR "%FILE2CHK%"
IF %ERRORLEVEL% EQU 0 GOTO :PreviousFileExists
GOTO :PreviousFileDoesNotExists


:RemoveLeadingZeroes
rem get the first digit and check if it is zero
SET P1=%SQNUM:~0,1%
IF "%P1" NEQ "0" GOTO :EOF
rem remove this leading zero
SET SQNUM=%SQNUM:~1%
GOTO :RemoveLeadingZeroes

:PreviousFileDoesNotExists
rem previous does not exist so this event should trigger
ECHO Y>"%WD_FILTERRESULT%"
GOTO :EOF

:PreviousFileExists
rem previous does exist so this event should be ignored
ECHO N>"%WD_FILTERRESULT%"
GOTO :EOF

[/code]

Title: Re: WD mail Notification Task for Folder Monitoring
Post by Shota Tadumadze on Mar 14th, 2017 at 9:23am
unfortunately it doesn't work, I created notification task with email plugin, in filter events: "when the extension equals txt then the file or directory is processed" and then added your script, the error code is, Error Code:18 with description: there are no more files.
I tried to edit your script, in this line, "rem the file to check for (C:\MonitorMe\*_b00432841.txt)" I edited path with my monitoring directory but results are the same and also the task shuts down itself after few seconds with same error code

Title: Re: WD mail Notification Task for Folder Monitoring
Post by Gert on Mar 14th, 2017 at 9:48am
Can you enable "debug" and run the task again until it stops. Then email (!!!!) me a backup so I can have a look. Full details here: http://blog-en.gdpsoftware.com/2010/06/send-task-backup-to-support.html

My email is below in my signature.

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