Page 1 of 1

Scripting command to update tagged/labeled items

Posted: 19 Jul 2025 14:18
by 1024mb
I often modify the names and/or locations of files from third party applications, the issue is that most of the times, as someone that uses labels and tags extensively, the entries become invalid and I lose the tags, if I'm lucky and I can track the old file and new file then I can manually "fix" it but most of the times not only the location changes but the name too so this is not possible to do. Also from my testings editing the tag db file manually is not reliable, if the path changes the lines have to be re-sorted and then we have to handle the tag refresh on the open XYplorer instance.

So all in all I would like to request a new command to update the paths in the tag database, the command could accept two args for old path and new path like:
tagitemrename("D:\somefolder\somefile", "D:\renamedfolder\renamedfile")

and it will handle all the internals.

Re: Scripting command to update tagged/labeled items

Posted: 19 Jul 2025 15:21
by highend

Code: Select all

    $srcItem = "D:\Temp\Arabic-ﻲسﺠ-characters.txt";
    $dstItem = "D:\Temp\xyz.txt";
    $result  = tagitemrename($srcItem, $dstItem);

function tagitemrename($srcItem, $dstItem) {
    $result  = 0;
    $content = readfile(<xytagdat>);
    $header  = gettoken($content, 1, "Data:<crlf>");
    $data    = gettoken($content, 2, "Data:<crlf>");
    $escaped = regexreplace($srcItem, "([\\^$.+()\[{])", "\$1");
    $newData = regexreplace($data, "^" . $escaped . "\|", $dstItem . "|");
    $newData = formatlist($newData, "ec", <crlf>);

    if ($data != $newData) { $result = writefile(<xytagdat>, $header . "Data:<crlf>" . $newData); }
    return $result;
}

Code: Select all

Before (snipped past "Data:"):
D:\Temp\Arabic-ﻲسﺠ-characters.txt|0|ﻲسﺠ|||||||||||||||||
D:\Temp\def.txt|0|def|||||||||||||||||

After:
D:\Temp\def.txt|0|def|||||||||||||||||
D:\Temp\xyz.txt|0|ﻲسﺠ|||||||||||||||||

Re: Scripting command to update tagged/labeled items

Posted: 17 Aug 2025 07:00
by 1024mb
Thanks! I didn't notice formatlist existed, I'm blind.