Page 2 of 2

Re: Tags from folder names

Posted: 20 Aug 2012 21:04
by highend
1. You have to upgrade your beta version again (to v11.40.0206)
2. I don't add so much user choices ;)
3. Try the new script

Remarks: If you select only one folder, it will let you select all parent folder names and the name of the folder as a tag as well. If you have more items selected, it will only let you selected parent folders from the current path.

Code: Select all

/* 19.08.2012, Tag files with their parent (grandparent etc.) folder names
   v11.40.0206 or up is required for "getpathcomponent"
   ::load "<xyscripts>\TagFiles.xys";
*/

	end (getinfo("CountSelected") < 1), "No file(s) or folder(s) selected, aborted!";

	$i = 1;
	$parentFolders = "";
	$countFolders = getpathcomponent(<curpath>, "count");
	if((getinfo("CountSelected") == 1) AND (exists(<curitem>) == 2)) {
		$parentFolders = "<curname>|";
	}

	while($i < $countFolders) {
		$parentFolders = $parentFolders . getpathcomponent(<curpath>, "component", $i +1). "|";
		$i++;
	}

	$tags = inputselect("Select all foldernames that should be used as tags for the current file selection:", $parentFolders, "|", 2); // Let's choose which foldernames should be written as tags
	$tags = replace($tags, "|", ",");
	end ($tags == ""), "No tag(s) selected, aborted!";

	$selectedItems = get("SelectedItemsPathNames", "|");
	foreach($item, $selectedItems) {
		if(exists($item) == 2) {
			$selected = folderreport("files", "r", $item, "r", , "|");
			tag $tags, $selected, 1, 0; // Add current tags with selected folder names as (new) tags
		} elseif(exists($item) == 1) {
			tag $tags, $item, 1, 0; // Add current tags with selected folder names as (new) tags
		}
	}

Re: Tags from folder names

Posted: 20 Aug 2012 23:41
by kiwichick
Hi highend, Thanks again for the latest incarnation, but was it your intention to make all tags unselected by default now? The last script had them all selected by default which makes more sense. Tagging still isn't quite being done the way I'd like but, between the two scripts you've posted, I can definitely get the job done. Cheers.

Re: Tags from folder names

Posted: 21 Aug 2012 00:37
by highend
but was it your intention to make all tags unselected by default now?
Yepp. If the folder hierarchy is a deep one it doesn't make much sense to select all parent folders by default. At least for me.

If you want to change it:

Code: Select all

$parentFolders = "<curname>|";
Change it to:

Code: Select all

$parentFolders = "+<curname>|";
And:

Code: Select all

$parentFolders = $parentFolders . getpathcomponent(<curpath>, "component", $i +1). "|";
To:

Code: Select all

$parentFolders = $parentFolders . "+" . getpathcomponent(<curpath>, "component", $i +1). "|";

Re: Tags from folder names

Posted: 21 Aug 2012 00:52
by kiwichick
Thanks once again highend, You guys are so helpful!!! Keep up the great work - XYplorer ROCKS :appl:

Re: Tags from folder names

Posted: 11 Sep 2012 03:16
by kiwichick
For anyone else who may be interested, this script works on selected Files, Folders and ALL selected Folder contents (files and subfolders no matter how deep they go). It can Add (not Set) Tags for Foldername, Parentname or Both. And it also has an option to Remove ALL existing Tags. Enjoy!

Code: Select all

"1 - Foldername|:showfolders"
   end(getinfo("CountSelected") < 1), "At least one File or Folder must be selected!";

   $lstF = get(selecteditemspathnames);

   foreach ($tkF, $lstF, "<crlf>") {

   $tst = exists($tkF);
   IF ($tst == "0") { end 1, "Script will close - No items were selected!"; }
   ELSEIF ($tst == "1") { $b = regexreplace("$tkF", "(.+\\).+", "$1"); $bfldr = gettoken($b, -2, "\"); tag "$bfldr", "$tkF", 1; continue 2; }
   ELSEIF ($tst == "2") {   }

   $lst = folderreport("items", "r", $tkF, "r");
   foreach ($tk, $lst, "<crlf>") {
   $b = regexreplace("$tk", "(.+\\).+", "$1");
   IF ($b == "") { continue; }
   ELSEIF ($b != "") {  }
   $bfldr = gettoken($b, -2, "\");
   tag "$bfldr", "$tk", 1;
                                 }

   $b = regexreplace("$tkF", "(.+\\).+", "$1");
   $bfldr = gettoken($b, -2, "\");
   tag "$bfldr", "$tkF", 1;
                                   }
   status "Tagging done!", "339933";

"2 - Parentname|:copyto"
   end(getinfo("CountSelected") < 1), "At least one File or Folder must be selected!";

   $lstF = get(selecteditemspathnames);

   foreach ($tkF, $lstF, "<crlf>") {

   $tst = exists($tkF);
   IF ($tst == "0") { end 1, "Script will close - No items were selected!"; }
   ELSEIF ($tst == "1") { $b = regexreplace("$tkF", "(.+\\).+", "$1"); $bfldr = gettoken($b, -3, "\"); tag "$bfldr", "$tkF", 1; continue 2; }
   ELSEIF ($tst == "2") {   }

   $lst = folderreport("items", "r", $tkF, "r");
   foreach ($tk, $lst, "<crlf>") {
   $b = regexreplace("$tk", "(.+\\).+", "$1");
   IF ($b == "") { continue; }
   ELSEIF ($b != "") {  }
   $bfldr = gettoken($b, -3, "\");
   tag "$bfldr", "$tk", 1;
                                 }

   $b = regexreplace("$tkF", "(.+\\).+", "$1");
   $bfldr = gettoken($b, -3, "\");
   tag "$bfldr", "$tkF", 1;

                                   }
   status "Tagging done!", "339933";

"3 - Both|:cucopy"
   end(getinfo("CountSelected") < 1), "At least one File or Folder must be selected!";

   $lstF = get(selecteditemspathnames);

   foreach ($tkF, $lstF, "<crlf>") {

   $tst = exists($tkF);
   IF ($tst == "0") { end 1, "Script will close - No items were selected!"; }
   ELSEIF ($tst == "1") { $b = regexreplace("$tkF", "(.+\\).+", "$1"); $bfldr2 = gettoken($b, -2, "\"); $bfldr3 = gettoken($b, -3, "\"); tag "$bfldr2, $bfldr3", "$tkF", 1; continue 2; }
   ELSEIF ($tst == "2") {   }

   $lst = folderreport("items", "r", $tkF, "r");
   foreach ($tk, $lst, "<crlf>") {
   $b = regexreplace("$tk", "(.+\\).+", "$1");
   IF ($b == "") { continue; }
   ELSEIF ($b != "") {  }
   $bfldr2 = gettoken($b, -2, "\");
   $bfldr3 = gettoken($b, -3, "\");
   tag "$bfldr2, $bfldr3", "$tk", 1;
                                 }

   $b = regexreplace("$tkF", "(.+\\).+", "$1");
   $bfldr2 = gettoken($b, -2, "\");
   $bfldr3 = gettoken($b, -3, "\");
   tag "$bfldr2, $bfldr3", "$tkF", 1;

                                   }
   status "Tagging done!", "339933";

"4 - Remove Tags|:tagsrmv"
    $lstF = get(selecteditemspathnames);

   end(getinfo("CountSelected") < 1), "At least one File or Folder must be selected!";

   foreach ($tkF, $lstF, "<crlf>") {

   $tst = exists($tkF);
   IF ($tst == "0") { end 1, "Script will close - No items were selected!"; }
   ELSEIF ($tst == "1") { tag "", "$tkF", 1; continue 2; }
   ELSEIF ($tst == "2") {   }

   $lst = folderreport("items", "r", $tkF, "r");
   foreach ($tk, $lst, "<crlf>") {
   tag "", "$tk", 1;
                                 }
   tag "", "$tkF", 1;
                                   }
   status "Tags removed!", "FF0000", alert;