Actions¶
Move¶
-
class
Move
(dest[, overwrite=False])¶ Move a file to a new location. The file can also be renamed. If the specified path does not exist it will be created.
If you only want to rename the file and keep the folder, it is easier to use the Rename-Action.
Parameters: - dest (str) – can be a format string which uses file attributes from a filter. If dest is a folder path, the file will be moved into this folder and not renamed.
- overwrite (bool) – specifies whether existing files should be overwritten. Otherwise it will start enumerating files (append a counter to the filename) to resolve naming conflicts. [Default: False]
- Examples:
Move into /some/folder/ and keep filenames
filters: - Move: {dest: '/some/folder/'}
Move to some/path/ and change the name to include the full date
- Move: {dest: '/some/path/some-name-{year}-{month:02}-{day:02}.pdf'}
Move into the folder Invoices on the same folder level as the file itself. Keep the filename but do not overwrite existing files (adds an index to the file)
- Move: {dest: '{path.parent}/Invoices', overwrite: False}
Copy¶
-
class
Copy
(dest[, overwrite=False])¶ Copy a file to a new location. If the specified path does not exist it will be created.
Parameters: - dest (str) – The destination where the file should be copied to. If dest ends with a slash / backslash, the file will be copied into this folder and keep its original name.
- overwrite (bool) – specifies whether existing files should be overwritten. Otherwise it will start enumerating files (append a counter to the filename) to resolve naming conflicts. [Default: False]
- Examples:
Copy all pdfs into ~/Desktop/somefolder/ and keep filenames
config.yaml¶rules: - folders: ~/Desktop filters: - Extension: pdf actions: - Copy: '~/Desktop/somefolder/'
Use a placeholder to copy all .pdf files into a PDF folder and all .jpg files into a .JPG folder. Existing files will be overwritten.
config.yaml¶rules: - folders: ~/Desktop filters: - Extension: - pdf - jpg actions: - Copy: dest: '~/Desktop/{extension.upper}/' overwrite: true
Copy into the folder Invoices. Keep the filename but do not overwrite existing files (adds an index to the file)
config.yaml¶rules: - folders: ~/Desktop/Invoices filters: - Extension: - pdf actions: - Copy: dest: '~/Documents/Invoices/' overwrite: false
Rename¶
-
class
Rename
(dest[, overwrite=False])¶ Renames a file.
Parameters: - name (str) – The new filename. Can be a format string which uses file attributes from a filter.
- overwrite (bool) – specifies whether existing files should be overwritten. Otherwise it will start enumerating files (append a counter to the filename) to resolve naming conflicts. [Default: False]
- Examples:
Convert all .PDF file extensions to lowercase (.pdf):
config.yaml¶rules: - folders: '~/Desktop' filters: - Extension: PDF actions: - Rename: "{path.stem}.pdf"
Convert all file extensions to lowercase:
config.yaml¶rules: - folders: '~/Desktop' filters: - Extension actions: - Rename: "{path.stem}{extension.lower}"
Trash¶
Shell¶
Python¶
-
class
Python
(code)¶ Execute python code in your config file.
Parameters: code (str) – The python code to execute - Examples:
A basic example that shows how to get the current file path and do some printing in a for loop. The
|
is yaml syntax for defining a string literal spanning multiple lines.config.yaml¶rules: - folders: '~/Desktop' actions: - Python: | print('The path of the current file is %s' % path) for _ in range(5): print('Heyho, its me from the loop')
You can access filter data:
config.yaml¶rules: - folders: ~/Desktop filters: - Regex: '^(?P<name>.*)\.(?P<extension>.*)$' actions: - Python: | print('Name: %s' % regex.name) print('Extension: %s' % regex.extension)
You have access to all the python magic – do a google search for each filename starting with an underscore:
config.yaml¶rules: - folders: ~/Desktop filters: - Filename: startswith: '_' actions: - Python: | import webbrowser webbrowser.open('https://www.google.com/search?q=%s' % path.stem)
Echo¶
-
class
Echo
(msg)¶ Prints the given (formatted) message. This can be useful to test your rules, especially if you use formatted messages.
Parameters: msg (str) – The message to print (can be formatted) - Example:
Prints “Found old file” for each file older than one year:
config.yaml¶rules: - folders: ~/Desktop filters: - LastModified: days: 365 actions: - Echo: 'Found old file'
Prints “Hello World!” and filepath for each file on the desktop:
config.yaml¶rules: - folders: - ~/Desktop actions: - Echo: 'Hello World! {path}'
This will print something like
Found a PNG: "test.png"
for each file on your desktop:config.yaml¶rules: - folders: - ~/Desktop filters: - Extension actions: - Echo: 'Found a {extension.upper}: "{path.name}"'