Filters

Extension

class Extension(*extensions)

Filter by file extension

Parameters:extensions – The file extensions to match (does not need to start with a colon).
Returns:
  • {extension} – the original file extension including colon.
  • {extension.lower} – the file extension in lowercase including colon.
  • {extension.upper} – the file extension in UPPERCASE including colon.

Examples:

  • Match a single file extension:

    config.yaml
    rules:
      - folders: '~/Desktop'
        filters:
          - Extension: png
        actions:
          - Echo: 'Found PNG file: {path}'
    
  • Match multiple file extensions:

    config.yaml
    rules:
      - folders: '~/Desktop'
        filters:
          - Extension:
            - jpg
            - jpeg
        actions:
          - Echo: 'Found JPG file: {path}'
    
  • Make all file extensions lowercase:

    config.yaml
    rules:
      - folder: '~/Desktop'
        filters:
          - Extension
        actions:
          - Rename: '{path.stem}{extension.lower}'
    
  • Using extension lists:

    config.yaml
    img_ext: &img
      - png
      - jpg
      - tiff
    
    audio_ext: &audio
      - mp3
      - wav
      - ogg
    
    rules:
      - folders: '~/Desktop'
        filters:
          - Extension:
            - *img
            - *audio
        actions:
          - Echo: 'Found media file: {path}'
    

Filename

class Filename(startswith='', contains='', endswith='', case_sensitive=True)

Match files by filename

Parameters:
  • startswith (str) – The filename must begin with the given string
  • contains (str) – The filename must contain the given string
  • endswith (str) – The filename (without extension) must end with the given string
  • case_sensitive = True (bool) – By default, the matching is case sensitive. Change this to False to use case insensitive matching.
Examples:
  • Match all files starting with ‘Invoice’:

    config.yaml
    rules:
      - folders: '~/Desktop'
        filters:
          - Filename:
              startswith: Invoice
        actions:
          - Echo: 'This is an invoice'
    
  • Match all files starting with ‘A’ end containing the string ‘hole’ (case insensitive)

    config.yaml
    rules:
      - folders: '~/Desktop'
        filters:
          - Filename:
              startswith: A
              contains: hole
              case_sensitive: false
        actions:
          - Echo: 'Found a match.'
    

LastModified

class LastModified(days=0, hours=0, minutes=0, seconds=0, mode='older')

Matches files by last modified date

Parameters:
  • days (int) – specify number of days
  • hours (int) – specify number of hours
  • minutes (int) – specify number of minutes
  • mode (str) – either ‘older’ or ‘newer’. ‘older’ matches all files last modified before the given time, ‘newer’ matches all files last modified within the given time.
Returns:

  • {lastmodified.year} – the year the file was last modified
  • {lastmodified.month} – the month the file was last modified
  • {lastmodified.day} – the day the file was last modified
  • {lastmodified.hour} – the hour the file was last modified
  • {lastmodified.minute} – the minute the file was last modified
  • {lastmodified.second} – the second the file was last modified

Examples:
  • Show all files on your desktop last modified at least 10 days ago:

    config.yaml
    rules:
      - folders: '~/Desktop'
        filters:
          - LastModified:
              - days: 10
        actions:
          - Echo: 'Was modified at least 10 days ago'
    
  • Show all files on your desktop which were modified within the last 5 hours:

    config.yaml
    rules:
      - folders: '~/Desktop'
        filters:
          - LastModified:
              - hours: 5
              - mode: newer
        actions:
          - Echo: 'Was modified within the last 5 hours'
    
  • Sort pdfs by year of last modification

    config.yaml
    rules:
      - folders: '~/Documents'
        filters:
          - Extension: pdf
          - LastModified
        actions:
          - Move: '~/Documents/PDF/{lastmodified.year}/'
    

Regex

class Regex(expr)

Matches filenames with the given regular expression

Parameters:expr (str) – The regular expression to be matched.

Any named groups in your regular expression will be returned like this:

Returns:
  • {regex.yourgroupname} – The text matched with the named group (?P<yourgroupname>)
Examples:
  • Match an invoice with a regular expression:

    config.yaml
    rules:
      - folders: '~/Desktop'
        filters:
          - Regex: '^RG(\d{12})-sig\.pdf$'
        actions:
          - Move: '~/Documents/Invoices/1und1/'
    
  • Match and extract data from filenames with regex named groups: This is just like the previous example but we rename the invoice using the invoice number extracted via the regular expression and the named group the_number.

    config.yaml
    rules:
      - folders: ~/Desktop
        filters:
          - Regex: '^RG(?P<the_number>\d{12})-sig\.pdf$'
        actions:
          - Move: ~/Documents/Invoices/1und1/{regex.the_number}.pdf