obsidian-vault-statistics-plugin
obsidian-vault-statistics-plugin copied to clipboard
Feature request: Show the amount of folders; also: empty files/folders
Thanks for your great plugin.
Is it possible to add the amount of folders? It would be great, if you also could show the amount of empty files and folders.
Greetings,
merlinuwe
Thanks for the suggestions. I'll consider adding these in a future update.
How do you envision the folder statistics working with sub-folders? Given the folder structure below:
|- foo/
|- bar/
|- baz/
|- bat/
|- bap.md
- Do you count all folders (
foo
,bar
,baz
,bat
), just the bottom-most folders (baz
,bat
), or something else? - Do you consider a folder that only contains sub-folders to be empty (e.g. is
bar
an empty folder?, what aboutfoo
?)
Good question. Make it as simple as possible, I'd suggest.
Solution 1: A folder is empty, if it holds no files. In your example, the following folders are empty:
foo bar baz
Only foo/bat is not empty, because it holds the file bap.md.
4 folders 3 empty folders
Solution 2: A folder is empty, if its last subfolder does not hold at least one file. In your example, the following folders are empty:
bar baz
Only foo/bat is not empty, because it holds the file bap.md.
4 folders 2 empty folders
An empty file:
A file (not: a folder) witch has no content. A file with no content is nonetheless a file and therefore counts as a file.
What do you think?
Thanks for this plugin. Bumping for interest.
Do you count all folders (foo, bar, baz, bat), just the bottom-most folders (baz, bat), or something else?
I would count any and all directories and sub-directories, regardless if they're empty or not. If a directory exists in the vault, count it. The example would therefore reflect a count of 4 directories. This is the default behavior of Obsidian when viewing the file and directory count by hovering over your vault's name.
Do you consider a folder that only contains sub-folders to be empty (e.g. is bar an empty folder?, what about foo?)
No. It's not empty because a directory exists, even if that directory is empty, that directory object is still there. This would be consistent with the above.
I haven't taken a very deep dive into the code myself, but the logic already mostly seems in collect.ts
to count directories, just not being utilized:
this.vault.getFiles().forEach((file: TFile) => {
if (!(file instanceof TFolder)) {
this.push(file);
} else {
// Count directory
}
});