Custom File Explorer plugin, multiple folders

Latest Obsidian, latest Custom File Explorer, MacOS 12.6.4.

I see posts that say, “The simplest case is to let the plugin take over the control of sorting of items in specified folder(s).”

Does anyone have an example of using one sortspec file to contain sorting specs for more than one folder? I can’t find an example to learn from.

For instance, I’d like one sortspec file in the root of my vault, controlling sort order in multiple folders in the vault, sorting each folder differently.

Is that possible?

So here is a custom example I’m using in my test vault:

sorting-spec: |
 // A simple configuration for obsidian-custom-sort plugin
 // (
 target-folder: .
  < true a-z
  > a-z 
 target-folder: ForumStuff/f51/f51093
 f51093 Combine md-files
 > true a-z
 target-folder: ForumStuff/f51/f51109
 > modified

Main folder . (aka ForumStuff)

This is the file ForumStuff/sortspec so by definitions the . refers to that main folder in the test vault. So the main sorting is related to that, and it says the following:

  • /:files – Create a new group related to the files, and…
    • < true a-z – sort these files in ascending order based on the true alpha-numeric sort (this means is related to how it would sort stuff like a1b, a2b and a10b)
  • /folders – After all the files have been listed, I then want to sort the group of folder, as
    • > a-z– Normal descending natural alphabetic order. (For me that would be that the folder f58 would come before the f57 folder)
  • % – Do all other stuff (if any present)
  • sortspec – Store the sortspec file itself at the very end of this group

Notice that for each group you need to be very careful with spaces, so sorting-spec is without spaces in front. Then target-folder and the group definitions and its sorting specifications have one space in front. Finally the specification related to the /:files and /folders they’ve got two spaces in front of them.

folder …/f51093

  • target-folder: ForumStuff/f51/f51093– Define the folder to sort
  • f51093 Combine md-files – Lift out this particular file to the top of list. Any file name specified are lifted out of the order specified related to this folder
  • > true a-z – True descending alphanumeric sorting of the other files. That is z first down to a at last. This is just for demonstration purposes in this post :slight_smile:

folder …/f51109

  • target-folder: ForumStuff/f51/f51109 – Yet another to folder somehow
  • > modified – Files are sorted related to last modification date, descending >. So that means, the last modified file is on top, with descending modification dates down the list.

Resulting sort of this specification

In the image above you see that the main folder of ForumStuff has the file first, before folders in descending order (aka the newest forum question first), f58, f57, …

After that within the f51093, the main file is sorted first, before the other files are in descending alphabetic order (just for the fun of it).

Finally within the f51109 files are sorted according to modification date (and I lastly changed the f51009 ... file so it appears at the top)

So this is one way to sort some folders, but there exist a myriad of options on how to do this. See plugin documentation for an extensive covering of sorting options.

It’s kind of hard to get started with, but as my example show it’s doable, and you’ll get the hang of it when paying proper attention to where to put spaces (or not) in front of the various elements.


Many thanks! I think I had a combination of errors. /:files, etc., indented more than target-folder, for one thing.

Your example speaks volumes and fixed everything.

1 Like

It looks to me like sortspec’s syntax is a little different from YAML’s lists and dictionaries.

One thing that got me is that a target-folder can be dot, or it can be path/to/folder, except path/to/folder can’t start with either dot or dot-slash and it can’t be just slash.

Everything is in the key-value pair sorting-spec, a multiline entry.

Everything under sorting -spec: | is indented equally except for /folders and /:files.

Sorting parameters under those keywords has additional indentation.

I think that’s correct. If there’s a low level description of sorting-spec’s construction, I haven’t found it. It’s possible I’m overlooking the obvious.

Either way, it’s working for me now.

Yeah, I’m not sure, but it surely is different from plain YAML. So it’s a little confusing, and I’ve just got it to work for my rather simplistic needs, and left it at that.

But it is very sensitive to indentation, so thread carefully.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.