Get File Extension and Size Properties

I am developing a plugin to track disc usage of folders and file types. I understand you can get the file properties of the active file using this.app.workspace.getActiveFile() and ending with stat.size and extension will get me the size in bytes and file type respectively. Is there some way to get this same information but across many files, or a directory of files?

I am imagining I will have to create a program similar to Linux’s du (disk usage) command, which I had this previously written in until I realized three flaws in this approach

  1. I would need sudo privileges
  2. I would need to rewrite it in powershell for Windows
  3. And I would need to figure out some solution for mobile.

I realized using Obsidian’s own API is likely the best route and would appreciate any advice or tips.

UPDATE: I just discovered app.vault.getFiles() which seems to solve my problem. This basically displays the same info as getActiveFile but for every file in the vault.

Take a look at this page of the developer documentation:

getAbstractFileByPath(path) - Get a file or folder inside the vault. If you need a file, you should test the returned object with instanceof TFile . Otherwise, if you need a folder, you should test it with instanceof TFolder .
getAllLoadedFiles() - Get all files and folders in the vault.
getFiles() - Get all files in the vault.
getMarkdownFiles() - Get all markdown files in the vault.

1 Like