Page 1 of 1
Automate tagging by applying tags from file to parent folder
Posted: 22 Dec 2020 07:24
by o7blue
Prior to trying out XYplorer I'd keep a folder.jpg and a tags.txt in a folder, and run a python script to format and add the tags inside tags.txt to folder.jpg as IPTC tags. This was only because I wasn't able to natively tag folders in Windows. Having tried XYplorer I'm now able to tag whole folders, but I was wondering if I can automate the whole process, or at least part of it. This is how I've done it with python:
tags.txt contents:
dog:
small
brown
cat:
chunky
long
python script to remove excess whitespace and properly group and flatten:
dog: small, dog: brown, cat: chunky, cat: long
python script to add tags delimited by comma to folder.jpg and done
Is it possible to achieve the same using XYplorer's scripting? The target here would be the parent folder of wherever tags.txt lives.
Re: Automate tagging by applying tags from file to parent folder
Posted: 22 Dec 2020 08:17
by highend
You were tagging a single "folder.jpg" file with the content of a file "tags.txt" before
The target is now "the parent folder".
What does that mean, do you want to write the tags from "tags.txt" to the parent folder now (and don't process the "folder.jpg" at all)?
E.g.:
Code: Select all
D:\Images\Christmas 2020\folder.jpg + tags.txt
and after using XYplorer all tags from tags.txt were written to "D:\Images\Christmas 2020"?
Re: Automate tagging by applying tags from file to parent folder
Posted: 22 Dec 2020 08:41
by o7blue
highend wrote: ↑22 Dec 2020 08:17
do you want to write the tags from "tags.txt" to the parent folder now (and don't process the "folder.jpg" at all)?
Yes, I'm keeping folder.jpg for the thumbnail, but attributing tags to it was just a stopgap solution. I should have done it in the original post, but here's a couple screenshots of what I want to achieve:
1.png
And the level above/parent folder:
2.png
So I need to 1- format the text inside tags.txt to preserve the group of each tag, and 2- use that formatted string to tag the parent folder. I hope the screenshots explain this well enough.
Re: Automate tagging by applying tags from file to parent folder
Posted: 22 Dec 2020 08:47
by highend
The only way to automate this (no user action necessary) is to assign a script to
"After browsing a folder" in "Changing Locations" in Configuration, General, Custom Event Actions
which would do the tagging each time you browse to a folder which has the "tags.txt" file in it
This requires a current beta version of XYplorer.
The way you'd normally do this (requires you to execute the script):
Browse into the root of some folder structures and let the script find all tags.txt files and let it do its work.
What do you prefer?
Re: Automate tagging by applying tags from file to parent folder
Posted: 22 Dec 2020 10:09
by o7blue
The second option (arbitrary user execution) is what I'm looking for. Since I have a lot of folders that each have their own tags.txt, doing it in bulk would be a very nice bonus.
Re: Automate tagging by applying tags from file to parent folder
Posted: 22 Dec 2020 10:47
by highend
Try this (and don't forget to switch into a root folder (that will contain tags.txt files somewhere in that folder structure)...
Re: Automate tagging by applying tags from file to parent folder
Posted: 22 Dec 2020 11:58
by o7blue
Your script does exactly what I need, and it's very robust too! I threw various malformed strings at it and different languages and it handled it all very well. But I found one character that breaks it:
https://apps.timwhitlock.info/unicode/inspect?s=%09
This whitespace character (I think it's a tab character?) messes with the script so that this (the tab is right after 'dog:'):
dog:
small
brown
cat:
chunky
long
becomes this:
$group brown, $group dog: , $group small, cat: chunky, cat: long
Is this possible to handle from within XYplorer? In any case thank you so much for writing this script, I did not expect to receive help so quickly or so on point!
Re: Automate tagging by applying tags from file to parent folder
Posted: 22 Dec 2020 12:13
by highend
Just redownload the attachment from
viewtopic.php?p=183757#p183757
or (if you want to change it manually) replace this line:
with this:
Code: Select all
$line = regexreplace($line, "(^[ \t]*|[ \t]*$)");
This will not only trim spaces but tabs (from both sides of a line) as well.
Btw, thanks for the donation!
Re: Automate tagging by applying tags from file to parent folder
Posted: 22 Dec 2020 13:04
by o7blue
With that regex magic the script works like a charm now! Thank you again for helping me out, I don't even want to think how long it would take me to come up with a solution that's not even half as good as yours
