Page 1 of 1

Sort folders by a file's tags in each sub-folder

Posted: 03 Feb 2015 18:45
by Imagine
I am looking for a new explorer, and seems like XYplorer is the best one out there. It meets all my requirements, but I am not sure about the following one. Can it do this?:
- Sort folders by a file's tags in each sub-folder

Details:
Folder-1
-Subfolder-1
---File.doc (Tag =b-text)
-Sub-folder-2
---File.doc (Tag =a-text)
-Subfolder-3
---File.doc (Tag =c-text)

I would like to see Folder-1 listing as:
-Subfolder 2
-Subfolder 1
-Subfolder 3

Re: Sort folders by a file's tags in each sub-folder

Posted: 03 Feb 2015 19:39
by bdeshi
You need to use a custom column.
My solution will only be helpful if your "file.doc"s are direct children of "subfolder"s (not located deeper than outlined) and have only one tag.

WARNING: This can make browsing in XYplorer slow if you have a lot of files in a lot of folders, and a lot of those folders in the active view.

first copy the following code.

Code: Select all

Snip: CustomColumn 1
  XYplorer 14.80.0225, 2/4/2015 12:29:43 AM
Action
  ConfigureColumn
Caption
  1st Child Tag
Type
  3
Definition
  //returns the first tag of the first tagged first-level child
   $lst = listfolder(<cc_item>);
   foreach($itm,$lst){
    $t = gettoken(tagitems(tags,,$itm),1,",");
    //$t = tagitems(tags,,$itm);
   //the line above will return all tags of first tagged child if you remove it's preceding //
    if ($t != ""){ break; }
   }
   return $t;
Format
  0
Trigger
  1
Item Type
  1
Item Filter
  
Now enter the following code into the addressbar and press ENTER. (Make sure the previous code is still copied to clipboard before pressing ENTER)

Code: Select all

::snippet <clipboard>;
now add a new column to the list :Menu -> View -> Columns -> Add Column. A new (Undefined) column will be added to the view.
Right click on it's title/header, choose "Select Custom Column", then pick "1st Child Tag".

Info: this column script will parse all children of a listed folder, get the first child that is tagged (if any), and return the first tag of that child.

It can be modifed to return ALL tags of the first tagged child of a listed folder. Look in the script.
It can also be modified to match the tags of all children against a taglist, and only return matched tags.
If can also be modified... you get the idea.

ed: Yay, my 1-and-a-half-thousand-th post! :o

Re: Sort folders by a file's tags in each sub-folder

Posted: 03 Feb 2015 19:43
by TheQwerty
The listing in the first post has the tagged item always being named 'File.doc'.
If that is indeed true then this can obviously be shortened dramatically and the impact to browsing would be significantly reduced. :wink:

Re: Sort folders by a file's tags in each sub-folder

Posted: 03 Feb 2015 19:58
by bdeshi
:kidding:
Yeah.
@Imagine: if that is indeed the case, then you can replace the part between (and icluding) Definition and Format with:

Code: Select all

Definition
   $i = "<cc_item>\File.Doc"; if (exists($i)==1){return gettoken(tagitems(tags,,$i),1,",")}
Format
:)

Re: Sort folders by a file's tags in each sub-folder

Posted: 04 Feb 2015 02:54
by Imagine
Thanks @SammaySarkar and @TheQwerty.

I will keep the file names standard (file.doc). I realized that the file would have more than one tags (e.g. Title, Owner, Category, etc). Say if I want to do a sort first by tag "Title" and then do a second sort by "Category", how would you modify the script?

Thanks!

Re: Sort folders by a file's tags in each sub-folder

Posted: 04 Feb 2015 05:56
by bdeshi
You have to use a fixed set of tags for each category for this to work.
Say you use the strings "Title_A", "Title_B" as the Title tag types. This custom column script will return first child tag matching these tags.
You can create additional columns for other tag categories.

Create a few copies of this column (just follow steps in my post above a few times) Find them in Tools -> Config -> Custom Columns.
modify the column title, paste the following as the script for each column, and modify $tags list (in the script) for each tag category.

Code: Select all

 //return first matching $tag of first child
 $tags = "Title_A|Title_B";
 $i = "<cc_item>\File.doc";
 if (exists($i)==1){return regexmatches(replacelist(tagitems(tags,,$i),", |,","<crlf>|<crlf>"),"^($tags)$")}