Scripting command to update tagged/labeled items

Features wanted...
Post Reply
1024mb
Posts: 228
Joined: 14 Dec 2018 23:26
Location: Windows 10 @ 100%

Scripting command to update tagged/labeled items

Post 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.

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

Re: Scripting command to update tagged/labeled items

Post 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|ﻲسﺠ|||||||||||||||||
One of my scripts helped you out? Please donate via Paypal

1024mb
Posts: 228
Joined: 14 Dec 2018 23:26
Location: Windows 10 @ 100%

Re: Scripting command to update tagged/labeled items

Post by 1024mb »

Thanks! I didn't notice formatlist existed, I'm blind.

Post Reply