Closed F5lx6k564f3 closed 4 years ago
Yes, this can be achieved with organize. You can use a python
-filter to parse the instructions and generate the new path.
For example:
rules:
- folders: "~/Documents/"
filters:
- extension:
- pdf
- docx
- filename:
contains: "_"
- python: |
import os
parts = []
instructions = dict()
for part in path.stem.split("_"):
if part.startswith("A-"):
instructions["A"] = part[2:]
elif part.startswith("V-"):
instructions["V"] = part[2:]
elif part.startswith("content-name"):
instructions["content"] = part[12:]
else:
parts.append(part)
return {
"new_path": os.path.join(*parts),
"instructions": instructions,
}
actions:
- echo: "New path: {python.new_path}"
- echo: "Instructions: {python.instructions}"
- echo: "Value of A: {python.instructions.A}"
- move: "~/Documents/{python.new_path}/{path.name}"
I'm closing this issue - if you have any issues with this feel free to reopen
No issues at the moment. Thanks!
I would like to include path/folder-instructions into the filename because I have a lot of different files (and there are always new categories added) I don't want create rules for. For example my filename is '2019_Jobs_CategoryA_TagB_A-Media_content-name_V01_draft_eng.docx' which means: Move the file to the folder '2019/Jobs/CategoryA/TagB/Media/drafts/eng' whereby 'A-' is an additional instruction and should be removed from the filename afterwards ('2019_Jobs_CategoryA_TagB_content-name_V01_draft_eng.docx').
I have a rough idea to figure it out with python but I'm new to it (see below a sketch). Is there a possibility to use such variables, conditions etc. with organizer natively? If no, is it possible to do it with Python in Organizer at all?