Page 1 of 1

Ignore files using a python script

Posted: Tue May 18, 2010 8:06 am
by Nepsir
Hi!

I'm trying to make a python script that will trigger a copy of a file only if the file doesn't contain !ut.
Before the script I have a DirectoryWatcher.Updated

The script looks like this:

Code: Select all

import shutil
filename = ''.join(eg.event.payload)
if filename.find(filename, '!ut') == -1:
	shutil.copy(filename,'D:\\shares\\Downloads\\therenamer\\therenamer TV Shows')
I'm getting the following error messages in the log:

Code: Select all

         Traceback (most recent call last):
           Python script "1", line 3, in <module>
             if filename.find(filename, '!ut') == -1:
         TypeError: slice indices must be integers or None or have an __index__ method
I think it's my lack in scripting that is the problem here...

I'm running 0.3.7.r1462 on a WHS machine.

Re: Ignore files using a python script

Posted: Tue May 18, 2010 9:55 am
by Pako

Code: Select all

import shutil
filename = ''.join(eg.event.payload)
if filename.find('!ut') == -1:
    shutil.copy(filename,'D:\\shares\\Downloads\\therenamer\\therenamer TV Shows')
Pako

Re: Ignore files using a python script

Posted: Tue May 18, 2010 10:28 am
by Nepsir
Pako wrote:

Code: Select all

import shutil
filename = ''.join(eg.event.payload)
if filename.find('!ut') == -1:
    shutil.copy(filename,'D:\\shares\\Downloads\\therenamer\\therenamer TV Shows')
Pako

Thank you so much!
Now it seems to ignore files containing !ut but now i get another error when it is a file that doesn't contain !ut:

Code: Select all

         Traceback (most recent call last):
           Python script "9", line 4, in <module>
             shutil.copy(filename,'D:\\shares\\Downloads\\therenamer\\therenamer TV Shows')
           File "shutil.pyc", line 88, in copy
           File "shutil.pyc", line 52, in copyfile
         IOError: [Errno 22] invalid mode ('rb') or filename: u'D:\\shares\\Downloads\\Unsorted TV Shows\\testing.aviD:\\shares\\Downloads\\Unsorted TV Shows\\testing.wmv'
Any ideas?

Re: Ignore files using a python script

Posted: Tue May 18, 2010 10:57 am
by Pako

Code: Select all

import shutil
for filename in eg.event.payload:
    if filename.find('!ut') == -1:
        shutil.copy(filename,'D:\\shares\\Downloads\\therenamer\\therenamer TV Shows')
Pako

Re: Ignore files using a python script

Posted: Tue May 18, 2010 11:12 am
by Nepsir
Pako wrote:

Code: Select all

import shutil
for filename in eg.event.payload:
    if filename.find('!ut') == -1:
        shutil.copy(filename,'D:\\shares\\Downloads\\therenamer\\therenamer TV Shows')
Pako
Again, thank you so much!
It seems to work now.