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.
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
- Luca Brasi
- Experienced User
- Posts: 262
- Joined: Sat Oct 11, 2008 12:39 pm
Re: Directory Watcher
Hey guys,
I have absolutely no clue about python. So I would like to ask for your help.
I think my task is a really simple...
This is what I want to do:
I want to trigger an action only if files with extensions like .avi,.mp4 or .srt are created.
I am sorry if this has been asked before but I couldn't find anything here.
I understand that I would need some sort of python script which analyses the payload.
Could someone of you please help me with this?
Thanks in advance
Luca
I have absolutely no clue about python. So I would like to ask for your help.
I think my task is a really simple...
This is what I want to do:
I want to trigger an action only if files with extensions like .avi,.mp4 or .srt are created.
I am sorry if this has been asked before but I couldn't find anything here.
I understand that I would need some sort of python script which analyses the payload.
Could someone of you please help me with this?
Thanks in advance
Luca
Win10 x64 Prof. / Eventghost latest / MCE Plugin / MCE RC6 Receiver / Logitech Harmony Hub / MediaPortal / kodi
-
valdolopes
- Posts: 2
- Joined: Sat Dec 01, 2012 3:52 pm
Re: Directory Watcher
Problems torrents that contain folders. If i download a torrent that is a file only, it works great, but if it is a file inside a folder the python script returns an error: IOError: [Errno 13] Permission denied: u'D:\\Documentos\\Organizar\\renomear\\')
Please do not find the solution anywhere
Please do not find the solution anywhere
Re: Directory Watcher
I'm not exactly sure what valdolopes is trying to say, but DirectoryWatcher can also watch subdirectories.
Luca try out this script:
or you could trigger a new event or whatever.
Luca try out this script:
Code: Select all
import shutil
import os
FileName = ''.join(eg.event.payload)
FileExtension = FileName[-3:]
isFolder = os.path.isdir(FileName)
if "avi" == FileExtension and isFolder == False:
shutil.move(FileName, "D:\\Downloads\\Movies")- Luca Brasi
- Experienced User
- Posts: 262
- Joined: Sat Oct 11, 2008 12:39 pm
Re: Directory Watcher
Thanks cfull1!
Working perfect! I tweaked the last line so an event will be triggered...
Any chance you could give a hint how I could only get only the filename and not the complete path of the file as payload? ("test.avi" and not "C:\Users\user1\Desktop\test.avi")
Working perfect! I tweaked the last line so an event will be triggered...
Any chance you could give a hint how I could only get only the filename and not the complete path of the file as payload? ("test.avi" and not "C:\Users\user1\Desktop\test.avi")
Win10 x64 Prof. / Eventghost latest / MCE Plugin / MCE RC6 Receiver / Logitech Harmony Hub / MediaPortal / kodi
Re: Directory Watcher
Hi Luca!Luca Brasi wrote:Thanks cfull1!
Working perfect! I tweaked the last line so an event will be triggered...
Any chance you could give a hint how I could only get only the filename and not the complete path of the file as payload? ("test.avi" and not "C:\Users\user1\Desktop\test.avi")
Here is my suggestion, although I'm not a python expert:
Code: Select all
import os
Path = ''.join(eg.event.payload)
FileName = Path.split('\\')[len(Path.split('\\'))-1]
FileExtension = FileName.split('.')[len(FileName.split('.'))-1]
isFolder = os.path.isdir(Path)
if "avi" == FileExtension and isFolder == False:
eg.TriggerEvent('Suffix','Payload','Prefix')Code: Select all
import os
Path = ''.join(eg.event.payload)
Path_split = Path.split('\\')
FileName = Path_split[len(Path_split)-1]
FileName_split = FileName.split('.')
FileExtension = FileName_split[len(FileName_split)-1]
isFolder = os.path.isdir(Path)
if "avi" == FileExtension and isFolder == False:
eg.TriggerEvent('Suffix','Payload','Prefix')1.- Path will be: C:\Users\Aitor\Desktop\Prueba\Movie.avi (Personal example)
2.- As files directories are separated by "\" in Windows, we will use the Python function "Split" to split the path. Path_split will be an array [u'C:', u'Users', u'Aitor', u'Desktop', u'Prueba', u'Movie.avi'] with 6 items.
3.- Although Path_split's length is 6, in Python array's are counted from 0..5, so if we want to take the last item of the array we need to do FileName = Path_split[len(Path_split)-1] = Path_split[6-1] = Path_split[5] = Movie.avi
4.- To take filename's extension we will follow the same approach, but instead of spliting with "\", using split('.') because filenames and it's extensions are always separated by dots. FileName_split = [u'Movie', u'xml']
5.- FileExtension again is going to be FileName_split[len(FileName_split)-1] = FileName_split[2-1] = FileName[1]. Remenber that FileName[0] = Movie because array's items start at 0.
Et voila.
Thinking about how directories and extensions are separated and with the split function you can make your personal scripts very easily and without great programming skills (believe me, it's my own case
If you have any question don't hesitate to ask, we are here to help each other
Best regards,
Aitor
- Luca Brasi
- Experienced User
- Posts: 262
- Joined: Sat Oct 11, 2008 12:39 pm
Re: Directory Watcher
Hi bodiroga/Aitor!
thank you so much for this! Your explanation is perfect and it is working great!
Very nice of you taking the time to explain this to me, I think this is a good start to try these scripts by myself...
)
Thanks again!
Luca
thank you so much for this! Your explanation is perfect and it is working great!
Very nice of you taking the time to explain this to me, I think this is a good start to try these scripts by myself...
Thanks again!
Luca
Win10 x64 Prof. / Eventghost latest / MCE Plugin / MCE RC6 Receiver / Logitech Harmony Hub / MediaPortal / kodi
Re: Directory Watcher
You're welcome LucaLuca Brasi wrote:Hi bodiroga/Aitor!
thank you so much for this! Your explanation is perfect and it is working great!
Very nice of you taking the time to explain this to me, I think this is a good start to try these scripts by myself...)
Thanks again!
Luca
You can change some part of the scripts according to this:
http://stackoverflow.com/questions/9303 ... -of-a-list
It's better to use the form Path_split[-1] rather tan Path_split[len(Path_split)-1). Shorter, faster and more elegant
Best regards and merry Christmas to all.
Aitor
Re: Directory Watcher
Hi Pako,
I know this thread is old and seems to have been derailed by another topic, but I wanted to ask you something about your python code that this thread was originally about.
I'm not good with python code, but it seems that the code checks to see if a file is being used, and if not it sets up DirectoryWatcher.AccessAllowed. However if the file is in use, it continues to check every 5 seconds? Is that correct?
If I only want to check 1 time, how do I edit this code to do that?
I know this thread is old and seems to have been derailed by another topic, but I wanted to ask you something about your python code that this thread was originally about.
I'm not good with python code, but it seems that the code checks to see if a file is being used, and if not it sets up DirectoryWatcher.AccessAllowed. However if the file is in use, it continues to check every 5 seconds? Is that correct?
If I only want to check 1 time, how do I edit this code to do that?
Re: Directory Watcher
I've been trying my best with this for the past couple days and no luck. Does anyone have any thoughts? I took Pako's code and removed some pieces so that I'm left with
My hope is that this would check if the file can be accessed, if it can, it sets up DirectoryWatcher2.AccessAllowed, otherwise it does nothing. Unfortunately, it doesn't appear to work as I'm expecting. I don't think it's setting up DirectoryWatcher2.AccessAllowed, or I'm doing something wrong
This is very new to me, so could be the latter.
Code: Select all
def CheckFileAccessFunction_1(filePath):
from os import path
f = None
if path.exists(filePath):
try:
f = open(filePath, 'ab+', 2)
if f:
eg.TriggerEvent("AccessAllowed",prefix="DirectoryWatcher2", payload=(filePath,))
finally:
if f:
f.close()Re: Directory Watcher
No one is able to help me out with this?
Re: Directory Watcher
I can not make the next with EG:
The event should be an url open, and the macro is speaker mute, but unfortunatelly, I can not make this...
How can I solve that If I launch a file or app, then do something automatically?
The event should be an url open, and the macro is speaker mute, but unfortunatelly, I can not make this...
How can I solve that If I launch a file or app, then do something automatically?
Re: Directory Watcher
Sorry for necroing and old thread but i've run into some problems with Directory Watcher.
I have it watching a network drive installed on my NAS (I do not think any permission problems are here) - So I have it watching z:/tvshows for example and i've pressed the button to "watch sub-directory" - when I create a folder in the tvshow folder everything is fine, but if i create a folder in tvshows/fargo for example the plugin does not detect anything.
Anyone know what can be wrong?
I have it watching a network drive installed on my NAS (I do not think any permission problems are here) - So I have it watching z:/tvshows for example and i've pressed the button to "watch sub-directory" - when I create a folder in the tvshow folder everything is fine, but if i create a folder in tvshows/fargo for example the plugin does not detect anything.
Anyone know what can be wrong?
Re: Directory Watcher
Is there a way to PREVENT this from reporting changes to folders within a directory? Only Files? Or is there another Plugin that does that?
-
cableghost
- Posts: 37
- Joined: Thu Oct 10, 2013 9:43 pm
Re: Directory Watcher
Is it possible to watch multiple directories? I can add another plugin, but what do I put in for the Event?
- Boolean263
- Plugin Developer
- Posts: 81
- Joined: Sat Aug 12, 2017 7:52 pm
- Location: Ottawa, Canada
- Contact:
Re: Directory Watcher
You're right, that you'll have to load multiple copies of the plugin. The second instance of the plugin will create events such as `DirectoryWatcher2.Updated`. This is handy if you want to do different things for different watched directories.cableghost wrote:Is it possible to watch multiple directories? I can add another plugin, but what do I put in for the Event?
If you want all your watched directories to trigger the same macro, the simplest way is to drag events from each plugin into your macro. You might also be able to use a wild-card event string, but I'm not clear what the syntax would be.
Windows 10 Home, version 1703, build 15063.540 ┬À EventGhost 0.5.0-rc4 ┬À wxPython 3.0.2.0
Python programmer for fun and profit. Dabbler in EventGhost plugin writing. Wiki gardener. General geek.
Python programmer for fun and profit. Dabbler in EventGhost plugin writing. Wiki gardener. General geek.