Append labels (as words) and tags to file names (selected)

Discuss and share scripts and script files...
AugerJ
Posts: 50
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ »

XYplorer 18.10.0000

Windows 8 Optimizations [Blue; Win8].mp4
(Win8 — set.)

"XYplorer File Tags v4

Labels:
Red|FC7469|010101;Orange|F3D2BC|010101;Yellow|F9F3BF|010101;Green|93C8B0|010101;Blue|6CB5FD|010101;Purple|E29CDD|010101;Grey|B5B5B5|010101;Roland_Juno-G|BE00C4|010101;White|FFFFFF|010101;Rose|FFD9EC|010101;Vinous|B86177|010101;Silver|E8F7F4|010101;Azure|00DFFF|010101;Khaki|62824A|010101;Gold|E4DAAF|010101

Extra Tags:
|0|0|0|||||
|0|0|0|||||
|0|0|0|||||
|0|0|0|||||
|0|0|0|||||

Storage: 1 (Relative to application drive)

Data: "

v18 is portable.

AugerJ
Posts: 50
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ »

I should've changed <xydata> to the actual path, shouldn't I?

AugerJ
Posts: 50
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ »

"
$labels = regexmatches(readfile("E:\Programs Portable\XYplorer 18.10.0000 (10-Jul-2017)\Data\tag.dat", , 2000), "^((.+?)\|\|(.+?)){7,}$");

"
Still doesn't work for labels.
There are spaces in the path. Or does XYplorer not require the path itself?

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Append labels (as words) and tags to file names (selected)

Post by highend »

Do not change <xydata>...

And try this:

Code: Select all

    end (compare(<xyver>, "18.00.0021", "v") == -1), "You need at least v18.00.0021 of XYplorer, aborted!";

    $labels = regexmatches(readfile("<xydata>\tag.dat", , 2000), "^((.+?)\|([A-F0-9]{6})?\|([A-F0-9]{6})){7,}$");
    $labels = trim(regexreplace($labels, "\|([A-F0-9]{6})?\|[A-F0-9]{6};?", "|"), "|");

    foreach($file, <get "SelectedItemsPathNames" <crlf>>, <crlf>, "e") {
        // Ignore folders
        if (exists($file) == 2) { continue; }

        // Find [<label name>;<tag>]
        $base = gpc($file, "base");
        $match = regexreplace(regexmatches($base, "\[[^]]*;[^]]*\]"), "\[|\]");
        if (!$match) { continue; }

        // Get label index from label name + tag
        $labelName = trim(gettoken($match, 1, ";"));
        $labelIndex = gettokenindex($labelName, $labels);
        $tag = trim(gettoken($match, 2, ";"));

        // Label + tag item
        if ($labelIndex) { tagitems("label", $labelIndex, $file); }
        if ($tag) { tagitems("tags", $tag, $file); }
    }
One of my scripts helped you out? Please donate via Paypal

AugerJ
Posts: 50
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ »

Yes! It works with every label, and with groups of files.
Thank you!

AugerJ
Posts: 50
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ »

Here I go again, after a while... Hello.
Turns out, this script:

Code: Select all

    end (compare(<xyver>, "18.00.0021", "v") == -1), "You need at least v18.00.0021 of XYplorer, aborted!";

    foreach($file, <get "SelectedItemsPathNames" <crlf>>, <crlf>, "e") {
        // Ignore folders
        if (exists($file) == 2) { continue; }

        $label = tagitems("label", , $file, 2);
        $tags  = tagitems("tags", , $file);

        if (!$label && !$tags) { continue; }
        else {
            $base = gpc($file, "base");
            $ext  = gpc($file, "ext");
            renameitem("$base [$label; $tags].$ext", $file);
        }
    }
doesn't update the [label; tag] parts of the file names,
it just adds, appends another [label; tag] part, so
File Name [label; tag].ext
becomes
File Name [label; tag] [label; tag].ext

Can this be fixed?

(XYplorer 18.20.0200)

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Append labels (as words) and tags to file names (selected)

Post by highend »

The $base in the renameitem() line already contains the old [tag; label]...
Remove it e.g. via a regexreplace() first
One of my scripts helped you out? Please donate via Paypal

AugerJ
Posts: 50
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ »

The $base in the renameitem() line already contains the old [tag; label]...
Remove it e.g. via a regexreplace() first
Sorry, I don't know how the script should look when finished.
Only "copy-paste" here, in this area...

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Append labels (as words) and tags to file names (selected)

Post by highend »

Code: Select all

$base = regexreplace(gpc($file, "base"), "([ ]+\[.+?\])");
One of my scripts helped you out? Please donate via Paypal

AugerJ
Posts: 50
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ »

Thank you.
Updated.

AugerJ
Posts: 50
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ »

highend wrote: 16 Jul 2017 16:04... and the [from label; from tag]
is removed from the file name?
Hello again. Actually, such a script (removing only the [from label; from tag] from the file name) might come in handy, if I wanted to share some files with "clean" names (while XYplorer would remember the labels and the tags).
And I don't know how to remove ' [from label; from tag]' with Search and Replace... , because the text inside the [] varies.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Append labels (as words) and tags to file names (selected)

Post by highend »

By reading the label + tag and then remove the combined "[some label; some tag]" from the file (base) name?
One of my scripts helped you out? Please donate via Paypal

AugerJ
Posts: 50
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ »

highend wrote: 07 Dec 2018 08:29 By reading the label + tag and then remove the combined "[some label; some tag]" from the file (base) name?
Yes. And the space before [ should be removed as well.
As in
" [some label; some tag]"

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Append labels (as words) and tags to file names (selected)

Post by highend »

Then go for it? All necessary elements (for loop, reading label + tag, renaming an item) are all part of the various script snippets in this thread...
One of my scripts helped you out? Please donate via Paypal

AugerJ
Posts: 50
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ »

Labels & Tags TO Delete in File Names.xys

Code: Select all

    end (compare(<xyver>, "18.00.0021", "v") == -1), "You need at least v18.00.0021 of XYplorer, aborted!";

    foreach($file, <get "SelectedItemsPathNames" <crlf>>, <crlf>, "e") {
        // Ignore folders
        if (exists($file) == 2) { continue; }

        $label = tagitems("label", , $file, 2);
        $tags  = tagitems("tags", , $file);

        if (!$label && !$tags) { continue; }
        else {
            $base = regexreplace(gpc($file, "base"), "([ ]+\[.+?\])");
            $ext  = gpc($file, "ext");
            renameitem("$base.$ext", $file);
        }
    }
Seems to work. I hope I haven't overlook anything.

Post Reply