Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File Trigger
#1
Using file trigger to monitor for *.txt files that have been added or modified which are written to a directory via ftp.

When a file gets added, the function runs for event 1 and event 8 even though I put the whole thing in a sel case statement where case [1,8] should catch added and modified, but it still runs for each event type.

Code:
Copy      Help
function event $name [$newname]
out
;event: 1 added, 2 removed, 4 renamed, 8 modified
out event
sel event
,case [1,8]
,str s.getfile(name)
,s.replacerx(".*?''" "" 4)
,str pattern="''(.*?)'':''(.*?)''"
,ARRAY(str) a
,findrx(s pattern 0 4 a)
,int i
,for(i 0 a.len)
,,out F"{a[1 i]}    {a[2 i]}"
#2
hi tested your function wouldn't work for me at all so i made a new function and it worked properly for me
except for when renaming.
when renaming while open in notepad gets this
1 C:\Users\Kevin\Documents\My QM\34.txt
1 C:\Users\Kevin\Documents\My QM\34.txt
8 C:\Users\Kevin\Documents\My QM\34.txt
i noticed if you rename the file while it is open in notepad qm thinks it a new file created and also its modified as well.
but if you rename from the folder without opening the file file trigger works correctly.



Function Function172
Trigger $f 0x449 "C:\" "*.txt"     Help - how to add the trigger to the macro
Code:
Copy      Help
;\
function event $name [$newname]
;event: 1 added, 2 removed, 4 renamed, 8 modified
int i = find(name "$RECYCLE.BIN");;added this so doesnt trigger when deleted to recycle bin
if i!-1;;added this so doesnt trigger when deleted to recycle bin
,end;;added this so doesnt trigger when deleted to recycle bin
sel event
,case 1
,out F"{event} {name}"
,out "added"
,case 2
,out F"{event} {name}"
,out "removed"
,case 4
,out F"{event} {name}"
,out "renamed"
,case 8
,out F"{event} {name}"
,out "modified"
#3
OS notifies QM about all file events each time when an application creates, writes ets a file. QM rejects duplicate events of same type, but not of different types.

Try this function.
Function FileTriggerSkipDuplicateEvent
Code:
Copy      Help
;/
function $name [^timeoutS]

;Call this from a file-triggered macro to join multiple events for a file to single event.
;Waits for next event for this file (name) max timeoutS seconds. If there is new event, ends this thread.
;Ignores event type. Should be used only with triggers where event types are 'created' and/or 'modified'.
;Default timeoutMS is 1 s.

;EXAMPLE
;function event $name [$newname]
;;event: 1 added, 2 removed, 4 renamed, 8 modified
;FileTriggerSkipDuplicateEvent name
;out F"{event} {name} {newname}"


if(!timeoutS) timeoutS=1
_s.encrypt(2|8)
__Handle ev=CreateEvent(0 0 0 F"QM FTSDE {_s}") ;;create or open event for this file
if(GetLastError=ERROR_ALREADY_EXISTS) SetEvent ev ;;if other thread already created event and waiting, set event, let it end
wait timeoutS H ev
err ret ;;timeout. Were no events for this file for timeoutS seconds.
end ;;other thread have set event for this file. End this thread, because other thread will process it.
#4
Dear Gintaras,

Does it exist a similar example in the case of window-Name Changed events - triggers?

This is my contribution, it was tested and worked. Any comments are welcome.

Function WindowTriggerSkipDuplicateEvent
Code:
Copy      Help
;/
function hwnd [^timeoutS]

if(!timeoutS) timeoutS=1
_s.encrypt(2|8)
__Handle ev=CreateEvent(0 0 0 F"QM FTSDE {_s}") ;;create or open event for this file
if(GetLastError=ERROR_ALREADY_EXISTS) SetEvent ev ;;if other thread already created event and waiting, set event, let it end
wait timeoutS H ev
err ret ;;timeout. Were no events for this file for timeoutS seconds.
end ;;other thread have set event for this file. End this thread, because other thread will process it.

Kind regards
#5
I would remove the _s.encrypt line and replace the string to "QM WTSDE {hwnd}".
#6
Many thanks.


Forum Jump:


Users browsing this thread: 1 Guest(s)