Table that lists folders and files inside them

I’m trying to create a table that lists the subfolders inside a folder, and the files inside the subfolders, like this

I can’t find how to do this with the Dataview table query, I assume it needs Dataview JS but I don’t enough knowledge on JS, to make sense of the table code I am seeing online.
I found this forum post with a similar concept, except the code there formats the results as a bulleted list.

For this table I only want to list one layer of subfolders inside the main folder, there are no sub-subfolders inside those subfolders.

Is there anyway to do this with Dataview?
Help much appreciated. Thanks!

Maybe you should use another plugin, called DataLoom by Trey Wallis.

This one is less complicated than custom code for Dataview, otherwise you’ll procrastinate only, imo

Untested code follows:

TABLE join(, " | ") as Files
GROUP BY file.folder as Folder

That could/should possibly do the trick. Maybe with a line in the middle (between table and group) if you want to limit it to a given folder, like:

FROM "My/Start/Folder"
TABLE join(, " | ") as Files
FROM "My/Start/Folder"
GROUP BY file.folder as Folder

Much thanks, this code works! But, if you don’t mind helping with some nitpicks …

The subfolders listed under the Folder column are printed as “Folder/Subfolder” any way to have them print as just “Subfolder”?

The file names under the Files column are also in reverse alphabetical order. I tried to sort them in alphabetical order using


but with no change, what’s the right way to write this?

Still untested, but maybe something like:

TABLE join(sort(, " | ") as Files
FROM "My/Start/Folder"
FLATTEN Regexreplace(file.folder, ".*/", "") as lastPart
GROUP BY lastPart as Folder
SORT lastPart

Not entirely sure if sorting the links works as expected, and the replace would fail if multiple subfolders exists. Then you might be better off doing something like substring(file.folder, xxx) where xxx is the length of your base folder.

Looks like there was a typo in your code: “Regexreplace” should be “regexreplace” in lowercase but with that it works perfect! Many thanks holroy.


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