- Rename a tag of selected items.gif (291.35 KiB) Viewed 6380 times
Rename a tag of selected items v1.1.xys- (1.33 KiB) Downloaded 101 times
Rename a tag of selected items.xys- (668 Bytes) Downloaded 253 times
Code: Select all
/*
***************************************************************************************************
@Function: Rename tags by list (and from tagged items)
@Created : 2022-07-28
@Modified: 2024-06-12
@Version : v0.1
***************************************************************************************************
*/
// Get tag list
#893; // Update tag list
tagexport("<xydata>\Database_backup\XYplorerTag(<date yymmdd-hhmm>).dat", "", 0); // Backup tags database
$taglist = formatlist(taglist(), "t", ","); // Get tag list
$selTags = replace(tagitems("tags", , , 1), "|", ","); // Gets the tags of the selected items
$selTags = formatlist($selTags, "sdt", ","); // Remove duplicate tags
$selTags = trim($selTags, ",");
// If the items has tags, then
if ($selTags) {
$newtaglist = formatlist($taglist, "f", ",", "!$selTags"); // Remove the tags to be checked from the tag list
$newtaglist = "+" . replace($selTags, ",", ",+") . ",$newtaglist"; // Check the tags of the selected items (add +) and combine them into a new tag list
} else {$newtaglist = $taglist}
// Open dialog
$renameTags = inputselect("Rename tags by list (and from tagged items)", "$newtaglist", "," ,3:=2+64+4096, "cancel", 500, 665, "XYplorer", , ":lstmgmt");
// Exit if no tags is selected
if ($renameTags == "") {status "No item was selected from the tag list.", "FF0000", "alert"; end '1==1';
} else { if ($renameTags == "cancel") {end '1==1'} }
$newTags = "";
foreach($tag, $renameTags, ",") {
$newTag = input("Rename tag: $tag", , $tag, "e", "cancel", 300, 171); // Pop-up dialog to modify
if ($newTag == "cancel") {end 1==1}
$newTags .= $newTag . ",";
}
$newTags = trim($newTags, ",");
status "Renaming tags: $renameTags";
taglist($renameTags, 2); // Remove from tag list
taglist($newTags, 1); // Add to tag list
// Find items with tags and rename the tags
$taggeditems = quicksearch("tags:" . replace($renameTags, ",", "|"), "%computer%"); // Find the checked tags in %computer%
if (!$taggeditems) {status "Renamed tags to: $newTags"; end 1==1}
showstatus 0; // Turn off the status bar display
foreach($item, $taggeditems, "<crlf>") {
$tags = tagitems("tags", , $item, 1); // Get the tags for each item
$nTags = formatlist($tags, "ft", ",", "!$renameTags"); // Remove tags
if ($nTags != $tags) {tagitems("tags", $newTags . "," . $nTags, $item);} // Add a new list of tags to each list item
}
showstatus; // Open the status bar display
status "Renamed tags to: $newTags"