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 (without colon)
  • {extension.lower} – the file extension in lowercase
  • {extension.upper} – the file extension in UPPERCASE

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. (default = ‘older’)
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}/'
    

Created

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

Matches files by created 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 created before the given time, ‘newer’ matches all files created within the given time. (default = ‘older’)
Returns:

  • {created.year} – the year the file was created
  • {created.month} – the month the file was created
  • {created.day} – the day the file was created
  • {created.hour} – the hour the file was created
  • {created.minute} – the minute the file was created
  • {created.second} – the second the file was created

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

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

    config.yaml
    rules:
      - folders: '~/Desktop'
        filters:
          - created:
              hours: 5
              mode: newer
        actions:
          - echo: 'Was created within the last 5 hours'
    
  • Sort pdfs by year of creation:

    config.yaml
    rules:
      - folders: '~/Documents'
        filters:
          - extension: pdf
          - created
        actions:
          - move: '~/Documents/PDF/{created.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