Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Directory watcher only triggers if a certain file extension

If you have a question or need help, this is the place to be.
Post Reply
z3us
Posts: 42
Joined: Fri Jul 29, 2011 2:35 am

Directory watcher only triggers if a certain file extension

Post by z3us »

Hi
I┬┤m using directory watcher to trigger an event, but I want this only to happen with a certain file extension (.png). Any help?
Thanks!
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Directory watcher only triggers if a certain file extens

Post by Pako »

PngFilter.png
PngFilter.png (4.69 KiB) Viewed 2295 times
Python Script content:

Code: Select all

from os.path import splitext
pld = eg.event.payload
fl = pld[0]
ext = splitext(fl)[1].lower()
if ext == '.png':
    eg.TriggerEvent("%s.%s" % (eg.event.suffix, "Png"), prefix=eg.event.prefix, payload = pld)
Pako
z3us
Posts: 42
Joined: Fri Jul 29, 2011 2:35 am

Re: Directory watcher only triggers if a certain file extens

Post by z3us »

It didn┬┤t work for me, the event is not filtered by extension.
Am I supposed to edit something in the script? I┬┤m sorry, but my python knwoledge is null
Attachments
eg.png
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Directory watcher only triggers if a certain file extens

Post by Pako »

z3us wrote:Am I supposed to edit something in the script?
There is no need to edit anything.
If the file type is .png, so in this case, a new event will be triggered.
Actions that need to do you have to put in another macro and assign new event to this macro.
Is that clear now?

Pako
z3us
Posts: 42
Joined: Fri Jul 29, 2011 2:35 am

Re: Directory watcher only triggers if a certain file extens

Post by z3us »

Yes, it┬┤s clear now, thanks
But no event is triggered
Attachments
eg.png
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Directory watcher only triggers if a certain file extens

Post by Pako »

z3us wrote:Yes, it┬┤s clear now, thanks
On the contrary, I see that you do not understand.
The Python Script should not be placed below the DirectoryWatcher.Created.Png event, but below the DirectoryWatcher.Created event.
Below the DirectoryWatcher.Created.Png event has to be placed something else (but I do not know what you do you intend to do with the file).

Pako
Attachments
PngFilter2.png
PngFilter2.png (8.43 KiB) Viewed 2284 times
z3us
Posts: 42
Joined: Fri Jul 29, 2011 2:35 am

Re: Directory watcher only triggers if a certain file extens

Post by z3us »

Thanks!
Post Reply