This is a similar case to your other question, so the code that I posted there needed little modification to get it to work in this instance.
You set up the rule in a similar way to the other rule, except that you define the matching rules to find any text files (or whichever kind of file you want this rule to apply to). The embedded script to use for the "shell script" is again, in Python, so you'll need to change the shell to "/usr/bin/python."
- Code: Select all
#!/usr/bin/env python
import os, sys, re, shutil;
# get all the folders in the current folder and then check to see if the file being processed matches any items in those folders
for item in os.listdir(os.getcwd()):
if os.path.isdir(item):
for subitem in os.listdir(item):
basename = os.path.basename(os.path.splitext(sys.argv[1])[0]);
expression = re.compile(basename, re.IGNORECASE);
if expression.search(subitem):
shutil.move(os.path.abspath(sys.argv[1]), item);
break;
Hope that helps. It seemed to work reasonably well for me when I tested it out. Note that if any file in the subfolder matches the file being matched, it will move that file into the subfolder immediately. Not sure if that's what you wanted, but it seems like the behavior you were looking for.