Batch rename with tags

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
ezne
Posts: 13
Joined: 24 Apr 2014 15:09

Batch rename with tags

Post by ezne »

Hello,

is there a way to batch rename files in order to easily append their tags and extra tags into their filenames?

Thank you for any help

highend
Posts: 14953
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Batch rename with tags

Post by highend »

Scripting?...

I'm away for the next 5-6 hours, if no one has written anything when I come back I'll do it.
One of my scripts helped you out? Please donate via Paypal

highend
Posts: 14953
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Batch rename with tags

Post by highend »

If you want to configure the divider (between filename, tag and extag(s))
modify the first line.

Try it with a few testitems first...

Code: Select all

    $div = "_"; // Select the divider character
    foreach($item, <get SelectedItemsPathNames |>) {
        $i = 0;
        $exTags = "";
        while ($i++ <= 5) {
            $exTag = tagitems($i, , $item);
            if ($exTag != "") { $exTags = $exTags . $exTag . $div; }
        }
        $tag = tagitems("tag", , $item);
        $exTag = trim($exTags, $div, "R");
        rename "b", "*$div$tag$div$exTag", , $item;
    }
One of my scripts helped you out? Please donate via Paypal

ezne
Posts: 13
Joined: 24 Apr 2014 15:09

Re: Batch rename with tags

Post by ezne »

Thank you very much!

It works well, as long as there are no filename illegal characters in tags. Would there be a possibility to substitute any of those characters with a '_' and preserve the rest of the tag?

highend
Posts: 14953
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Batch rename with tags

Post by highend »

Sure.
The pipe symbol doesn't need to be replaced, it isn't allowed in tags by default.

Code: Select all

    $div = "_"; // Select the divider character
    $legal = "_"; // Select the legal char that replaces illegal characters
    foreach($item, <get SelectedItemsPathNames |>) {
        $i = 0;
        $exTags = "";
        while ($i++ <= 5) {
            $exTag = tagitems($i, , $item);
            if ($exTag != "") { $exTags = $exTags . $exTag . $div; }
        }
        $tag = tagitems("tag", , $item);
        $exTag = trim($exTags, $div, "R");
        $fileName = regexreplace("$tag$div$exTag", "[<>:""/\\?*]", "$legal");
        rename "b", "*$div$fileName", , $item;
    }
One of my scripts helped you out? Please donate via Paypal

ezne
Posts: 13
Joined: 24 Apr 2014 15:09

Re: Batch rename with tags

Post by ezne »

Sweet! Thank you! :D

Post Reply