Dataview count of sub-projects

I am importing notes from another program. My vault has a folder SnipNotes inside which there are folders for each of the top level groups used in that app, e.g. ARCHIVE, <Notes>, <Temp>… Each of those may contain more folders and/or notes.

Is there any way to get a list of each top level folder and a count of the items it holds?

I’d rather not have to add anything to the existing notes if possible. I want to ty and keep it as generic as possible so I can use it elsewhere. I don’t want to assume I know the folder names either. I just want a method of parsing one level of folders if that is possible.

In the ARCHIVE folder there are 4 notes, <Notes> has 248 and so on.

The Mac directory is:
Screenshot 2022-05-20 at 12.01.15

The Main Index.md file is:
Screenshot 2022-05-20 at 11.31.28

Each folder has an Index.md file that also has the YAML property ‘Index: 1’ which is how I get just those files for the main Index.

Main Index.md shows:

Which is great, I’d just like the Count field on the end of each row to tell me how many notes are in each.

As an example, the Index.md within ARCHIVE:


So the count for ARCHIVE would be 4.

Apologies if this is confusing. Just started looking at Obsidian and I don’t know the correct terminology for these items.

Mark

The …

plugin will show it to you in the file explorer if that is of use to you.

I can isolate the top two folders I require with:

join(split(file.folder,"/",2),"/") AS TEST

So:

TABLE file.folder, join(split(file.folder,"/",2),"/") AS TEST
WHERE startswith(file.folder, "SnipNotes") AND file.name != this.file.name
GROUP BY file
LIMIT 10

So I get “SnipNotes/ARCHIVE” for example. But I can’t use that to restrict the data. Is it possible to nest dataview queries?

That way I could get the “SnipNotes/xxx” as FirstQueryList, then run through that as a second query where the from was something like:

WHERE startswith(file.folder, FirstQueryList) AND file.name != this.file.name

I’ll have a look but I wanted it in the table really.

Some points in DQL perspective (not comfortable to give you advice in JS).
The main problem is: in some way, to achieve the count in the same query (yes, in dql you can’t use nested queries) you need to call ALL files in that folders… not only the index files.
For example, if you use this:

TABLE WITHOUT ID
	rows.file.link,
	dateformat(rows.file.ctime, "yyyy-MM-dd HH:mm") AS "cTime",
	dateformat(rows.file.mtime, "yyyy-MM-dd HH:mm") AS "mTime",
	length(rows) AS Count
WHERE startswith(file.folder, "SnipNotes/")
GROUP BY file.folder AS F

And now?
You can’t do much more…
To solve your problem with a query where you filter your INDEX files, maybe you need a specific field in each index file with the number of files in that folder…
Something like:

count:: `$= --dvjs - query--to--calculate--files--for--that--folder`

And then, in your global query, adding the field count

It’s dirty, but I think it should work

Just did this on my readwise folder

TABLE WITHOUT ID  split(join(rows.file.folder),",",1) AS "FOLDER", length(rows.file.link) AS "NUM"
FROM "readwise"
GROUP by file.folder

This is close:

TABLE file.folder, join(split(file.folder,"/",2),"/") AS TEST, length(rows) AS Count
WHERE startswith(file.folder, "SnipNotes/") AND file.name != this.file.name
SORT file.folder ASC
GROUP BY join(split(file.folder,"/",2),"/") AS T2

Gives:

But the Group isn’t showing the proper names. file.folder is empty and TEST is null! Very odd. The counts look right and the groups are getting there which are the important bits.

gregp: just tried this on mine and I get a list for every note:

Ah, I think it might be connected with the folder names, All the blank ones are of the form <Test> so the angle brackets seem to upset things.

I renamed <Current> to Current and I get:

using:

TABLE join(split(file.folder,"/",2),"/") AS TEST, length(rows) AS Count
WHERE startswith(file.folder, "SnipNotes/") AND file.name != this.file.name
SORT file.folder ASC
GROUP BY join(split(file.folder,"/",2),"/") AS T2

So is there anything I can do other than renaming the folders?
And why is TEST listed as null rather than e.g. SnipNotes/Current?

I renamed all but one, so I can try and find a solution. Instead of <> I used [], which brings another problem.

In the first table those names end with a white ] it’s just cosmetic but it is really irritating my OCD.

Oh, and then I need someway to merge the two, or make the 'Group' open the relevant index e.g. 'SnipNotes/Current/Index.md'.

Well, I don’t understand well your direction at this point.
What’s your goal at this moment?
(going back to my first post, I miss the point related with “top level” groups).

At this moment, what you obtain with this query?

TABLE WITHOUT ID
	filter(rows, (r) => r.index).file.link AS File,
	dateformat(filter(rows, (r) => r.index).file.ctime, "yyyy-MM-dd HH:mm") AS "cTime",
	dateformat(filter(rows, (r) => r.index).file.mtime, "yyyy-MM-dd HH:mm") AS "mTime",
	length(rows) AS Count
WHERE startswith(file.folder, "SnipNotes/")
GROUP BY join(split(file.folder,"/",2),"/") AS F

Basically my last post is close.

I would like a list of the top-level folders within the SnipNotes folder, with a count against each of how many notes are in them.

This seems to do that:

The bottom table has the folders and counts, the 4th one up should be SnipNotes/<TMP> the angle brackets seem to cause problems. So I’d like to know if there is a way to fix that.

In the top table, folders using square brackets are displayed badly, the text is purple except for the closing bracket which is white. I’d like to know if that can be fixed.

What I would eventually like is a combination of the two, so in the bottom table it would have a link field like the purple ones in the top table which when clicked would open up e.g. SnipNotes/Current/Index.md.

Hope that isn’t as confused as it sounds!

Result of your code is:

Dataview: Error: 
-- PARSING FAILED --------------------------------------------------

> 1 | TABLE WITHOUT ID filter(rows, (r) => r.index).[file.link](http://file.link/) AS File, dateformat(filter(rows, (r) => r.index).file.ctime, "yyyy-MM-dd HH:mm") AS "cTime", dateformat(filter(rows, (r) => r.index).file.mtime, "yyyy-MM-dd HH:mm") AS "mTime", length(rows) AS Count WHERE startswith(file.folder, "SnipNotes/") GROUP BY join(split(file.folder,"/",2),"/") AS F
    |                                               ^
  2 | 

Expected:

variable identifier

what do you with the code?
everything in same line and pasted not in plain text?

code.md (369 Bytes)

Pasted in same as my own ones.

Anyway, loaded yours as a file and got:

don’t you have notes with the field index?

The code for mine is:

TABLE join(split(file.folder,"/",2),"/") AS TEST,length(rows) AS Count
WHERE startswith(file.folder, "SnipNotes/") AND file.name != this.file.name
SORT file.folder ASC
GROUP BY join(split(file.folder,"/",2),"/") AS T2

notes inside each top-level folder