New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Filter for common file prefixes/suffixes #153
Labels
Comments
Little dirty, but this is how I've implemented it now: rules:
- enabled: true
folders:
- ~/Downloads/
filters:
- python: |
import os, os.path
from collections import Counter
files = os.listdir(basedir)
parts = path.name.split(' ')
counter = Counter()
for i in range(len(parts) + 1):
prefix = ' '.join(parts[0:i])
counter[prefix] = len([i for i in files if i.startswith(prefix)])
del counter['']
prefix = ''
count = 1
for (p, c) in counter.most_common(2):
if len(p) > len(prefix):
prefix = p
count = c
if count == 1 or len(prefix) <= 3:
return False
return {
'prefix': prefix.strip(),
'count': count,
'suffix': path.name.replace(prefix, '', 1).strip()
}
actions:
- move: '{basedir}/{python.prefix}/{python.suffix}'
|
Nice, do you mind if I take your code as a starting point for a built-in filter? |
@tfeldmann yeah of course, go ahead :) |
I randomly thought about this. I guess this could have been a regex: rules:
- locations: .
filters:
- regex: '^(?P<podcast>.+?) (?P<episode>Ep \d+\.mp3)'
actions:
- move: './{regex.podcast}/{regex.episode}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a flat directory with various different files which all start with common prefixes, eg:
Would it be possible to create a filter which matches common prefixes in files, allowing you to group these files into related folders? Eg:
Output:
The text was updated successfully, but these errors were encountered: