Actions¶
Move¶
-
class
Move
(dest[, overwrite=False][, counter_separator=' '])¶ 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) – The destination folder or path. If dest ends with a slash / backslash, 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]
- counter_separator (str) – specifies the separator between filename and the appended counter.
Only relevant if overwrite is disabled. [Default:
' '
]
- Examples:
Move all pdfs and jpgs from the desktop into the folder “~/Desktop/media/”. Filenames are not changed.
rules: - folders: ~/Desktop filters: - extension: - pdf - jpg actions: - move: '~/Desktop/media/'
Use a placeholder to move all .pdf files into a “PDF” folder and all .jpg files into a “JPG” folder. Existing files will be overwritten.
rules: - folders: ~/Desktop filters: - extension: - pdf - jpg actions: - move: dest: '~/Desktop/{extension.upper}/' overwrite: true
Move pdfs into the folder Invoices. Keep the filename but do not overwrite existing files. To prevent overwriting files, an index is added to the filename, so
somefile.jpg
becomessomefile 2.jpg
.rules: - folders: ~/Desktop/Invoices filters: - extension: - pdf actions: - move: dest: '~/Documents/Invoices/' overwrite: false counter_separator: '_'
Copy¶
-
class
Copy
(dest[, overwrite=False][, counter_separator=' '])¶ 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]
- counter_separator (str) – specifies the separator between filename and the appended counter.
Only relevant if overwrite is disabled. [Default:
' '
]
- Examples:
Copy all pdfs into ~/Desktop/somefolder/ and keep filenames
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.
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. To prevent overwriting files, an index is added to the filename, so somefile.jpg becomes somefile 2.jpg. The counter separator is ‘ ‘ by default, but can be changed using the counter_separator property.
rules: - folders: ~/Desktop/Invoices filters: - extension: - pdf actions: - copy: dest: '~/Documents/Invoices/' overwrite: false counter_separator: '_'
Rename¶
-
class
Rename
(dest[, overwrite=False][, counter_separator=' '])¶ 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]
- counter_separator (str) – specifies the separator between filename and the appended counter.
Only relevant if overwrite is disabled. [Default:
' '
]
- Examples:
Convert all .PDF file extensions to lowercase (.pdf):
rules: - folders: '~/Desktop' filters: - extension: PDF actions: - rename: "{path.stem}.pdf"
Convert all file extensions to lowercase:
rules: - folders: '~/Desktop' filters: - Extension actions: - rename: "{path.stem}.{extension.lower}"
Trash¶
-
class
Trash
¶ Move a file into the trash.
- Example:
Move all JPGs and PNGs on the desktop which are older than one year into the trash:
rules: - folders: '~/Desktop' - filters: - lastmodified: - days: 365 - extension: - png - jpg - actions: - trash
Shell¶
-
class
Shell
(cmd: str)¶ Executes a shell command
Parameters: cmd (str) – The command to execute. - Example:
(macOS) Open all pdfs on your desktop:
rules: - folders: '~/Desktop' filters: - extension: pdf actions: - shell: 'open "{path}"'
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.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:
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:
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:
rules: - folders: ~/Desktop filters: - lastmodified: days: 365 actions: - echo: 'Found old file'
Prints “Hello World!” and filepath for each file on the desktop:
rules: - folders: - ~/Desktop actions: - echo: 'Hello World! {path}'
This will print something like
Found a PNG: "test.png"
for each file on your desktop:rules: - folders: - ~/Desktop filters: - Extension actions: - echo: 'Found a {extension.upper}: "{path.name}"'
Show the
{basedir}
and{path}
of all files in ‘~/Downloads’, ‘~/Desktop’ and their subfolders:rules: - folders: - ~/Desktop - ~/Downloads subfolders: true actions: - echo: 'Basedir: {basedir}' - echo: 'Path: {path}'