Ignore files using a python script

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
Nepsir
Posts: 3
Joined: Tue May 18, 2010 7:52 am

Ignore files using a python script

Post by Nepsir » Tue May 18, 2010 8:06 am

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.

User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Ignore files using a python script

Post by Pako » Tue May 18, 2010 9:55 am

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

Nepsir
Posts: 3
Joined: Tue May 18, 2010 7:52 am

Re: Ignore files using a python script

Post by Nepsir » Tue May 18, 2010 10:28 am

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?

User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Ignore files using a python script

Post by Pako » Tue May 18, 2010 10:57 am

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

Nepsir
Posts: 3
Joined: Tue May 18, 2010 7:52 am

Re: Ignore files using a python script

Post by Nepsir » Tue May 18, 2010 11:12 am

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.

Post Reply