Script to remove tags by inputselect

Discuss and share scripts and script files...
kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Script to remove tags by inputselect

Post by kiwichick »

Hi there, I've written a script that will list the tags of the selected item in an inputselect window. The tags can be selected via checkbox and the selected tags are to be removed. The only problem is it won't remove the item's final tag. So if an item has 7 tags it will remove any of the first 6 but not the last one. Can someone please tell me why and how to fix it? Cheers.

Code: Select all

//doesn't remove last existing tag
$a = report("{tags}<crlf>", 1);
   $b = inputselect("Select Tags to Remove.<crlf> Tags will be removed from the selected File or Folder", $a,", ",2);
   tag "$b", ,1,2;
Windows 10 Pro 22H2

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: Script to remove tags by inputselect

Post by Marco »

Try this ;)

Code: Select all

//doesn't remove last existing tag
$a = report("{tags}", 1);
   $b = inputselect("Select Tags to Remove.<crlf> Tags will be removed from the selected File or Folder", $a,", ",2);
   tag "$b", ,1,2;
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: Script to remove tags by inputselect

Post by kiwichick »

Thanks heaps Marco, Gosh it's the littlest things sometimes. So much to learn :shock:
Windows 10 Pro 22H2

LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

Re: Script to remove tags by inputselect

Post by LittleBiG »

Marco wrote:Try this ;)

Code: Select all

//doesn't remove last existing tag
$a = report("{tags}", 1);
   $b = inputselect("Select Tags to Remove.<crlf> Tags will be removed from the selected File or Folder", $a,", ",2);
   tag "$b", ,1,2;
It doesn't seem ok. Try this instead:

Code: Select all

//tag remove  
   $b = inputselect("Select Tags to Remove.<crlf> Tags will be removed from the selected File or Folder", formatlist(report("{tags}, ", 1),"eds",", "),", ",2); 
   if $b != "" {tag "$b", ,1,2};

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: Script to remove tags by inputselect

Post by Marco »

LittleBiG wrote:It doesn't seem ok...
I can confirm that it works.
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

Re: Script to remove tags by inputselect

Post by LittleBiG »

Marco wrote:
LittleBiG wrote:It doesn't seem ok...
I can confirm that it works.
I have 3 files with 3 different tags. (1 file - 1 tag). Your script concatenates my 3 tags, then gives me 1 choice to remove.

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: Script to remove tags by inputselect

Post by Marco »

LittleBiG wrote:I have 3 files with 3 different tags. (1 file - 1 tag). Your script concatenates my 3 tags, then gives me 1 choice to remove.
You're doing it wrong, the script is intended to work on a single file/folder.
...a script that will list the tags of the selected item in an inputselect window...

Code: Select all

...Tags will be removed from the selected File or Folder...
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

Re: Script to remove tags by inputselect

Post by LittleBiG »

Ok, I see.

kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: Script to remove tags by inputselect

Post by kiwichick »

OMG LittleBiG!!! Thank you so so so much :appl: Yes my script concatenates the tags when multiple selections are made. That's why, as Marco pointed out, it's only intended to work on one file or folder. My next mission was to see if I could work out how to make it work on multiple selections (and then concede defeat and post back here with a request) :oops: But you've done it for me - and probably saved me hours of trying. Absolutely loving XYplorer!!!!!!!
Windows 10 Pro 22H2

kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: Script to remove tags by inputselect

Post by kiwichick »

OK the script as it is will remove tags from selected item(s) only which means if a folder is selected only the folder itself is affected and not recursively (the folder contents). So I've managed to incorporate part of this script with part of another script I have that will remove tags recursively and it works a treat!!!

Code: Select all

"Remove inputselect Tags recursively|:tagsrmv"
   end(getinfo("CountSelected") < 1), "At least one item must be selected!";
   $lstF = get(selecteditemspathnames);
   $a = inputselect("Select Tags to Remove.<crlf> Tags will be removed recursively (selected files, folders and folder contents).", formatlist(report("{tags}, ", 1),"eds",", "),", ",2);
   foreach ($tkF, $lstF, "<crlf>") {
   tag "$a", "$tkF", 1, 2;
   $lst = folderreport("items", "r", $tkF, "r");
   foreach ($tk, $lst, "<crlf>") {
   tag "$a", "$tk", 1, 2;
   }
   tag "$a", "$tkF", 1, 2;
   }
The next evolution I've been trying to figure out is, inputselect shows the tags of the selected items only. If a folder is selected sometimes the contents will have different tags to the folder and I would like to have these tags shown by inputselect as well. As always any help you guys provide is gratefully accepted :biggrin:
Windows 10 Pro 22H2

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

Re: Script to remove tags by inputselect

Post by highend »

Code: Select all

"Remove inputselect Tags recursively|:tagsrmv"
   end(getinfo("CountSelected") < 1), "At least one item must be selected!";
   $lstF = get("selecteditemspathnames", "|");

   $tagLst = "";
   $filesLst = "";
   foreach($item, $lstF, "|") {
		if(exists($item) == 2) {
			$tags = folderreport("files:{tags}", "r", $item, "r", , "|");
			$files = folderreport("files", "r", $item, "r", , "|");
		} else {
			$tags = report("{tags}", $item);
			$files = $item;
		}
		$tagLst = $tagLst . $tags . "|";
		$filesLst = $filesLst . $files . "|";
   }
   $tagLst = replace($tagLst, ",", "|");
   $tagLst = formatlist($tagLst, "edst", "|"); // Clean the tag list

   $a = inputselect("Select Tags to Remove.<crlf> Tags will be removed recursively (selected files, folders and folder contents).", $tagLst, "|" , 2);
   tag "$a", $filesLst, 1, 2;
One of my scripts helped you out? Please donate via Paypal

kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: Script to remove tags by inputselect

Post by kiwichick »

OMG almost, highend!!! It removes tags from the selected folder's contents recursively YAY! Except, if the selected folder contains a subfolder, tags are removed from the subfolder's contents but not the subfolder itself.
Windows 10 Pro 22H2

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

Re: Script to remove tags by inputselect

Post by highend »

Then replace the "files" with "items" in the folderreport() commands?
One of my scripts helped you out? Please donate via Paypal

kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: Script to remove tags by inputselect

Post by kiwichick »

Yes that removes tags from the selected folder's contents including subfolders but it doesn't remove tags from the selected folder :?
Windows 10 Pro 22H2

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

Re: Script to remove tags by inputselect

Post by highend »

Which is a completely different issue than your last post.

Include the the parent folder via:

Code: Select all

			$tags = report("{tags}", $item) . "|" . folderreport("items:{tags}", "r", $item, "r", , "|");
			$files = $item . "|" . folderreport("items", "r", $item, "r", , "|");
One of my scripts helped you out? Please donate via Paypal

Post Reply