Note with a hierarchical list of existing notes in it

Is there a way I could automatically have a note with a list of all the notes I already have?

  • I need it to have auto update,
  • be in a form of an internal link to that note,
  • and be hierarchical, so that the name of a folder will be a heading and below will be a list of notes in that folder (as links to them)

Does anyone knows some plugin or other ways I could achieve that?

1 Like

This looks like it might work for you…

```dataview
LIST rows.file.link
SORT file.path
GROUP BY file.folder
```

https://blacksmithgu.github.io/obsidian-dataview/queries/query-types/#grouping

1 Like

Thank you very much! It helped!!

Could you tell me how can I add canvas to the list as well?
And I wonder if there’s a way to make sub folders as a nested list, like when using tab? and make all folders names bold?

From my quick research, Dataview doesn’t support canvas files with a standard query. You can use the more powerful dataviewjs query.

These both could also be accomplished with a dataviewjs query.

A dataviewjs query is more involved to write. In this case, I’ll leave this as an exercise for the reader :grin:

1 Like

soo I checked that snippet, it didn’t FULLY worked as I needed it to, so I asked Ai to change it a little bit, and it workedх perfectly! I’m gonna leave it here

const canvas = app.vault.getFiles()
    .filter(file => file.extension === 'canvas')
    .sort((a, b) => a.name.localeCompare(b.name));

// Group files by folders
const groupedByFolder = {};
canvas.forEach(file => {
    const folder = file.path.split('/').slice(0, -1).join('/') || 'Root directory';
    if (!groupedByFolder[folder]) {
        groupedByFolder[folder] = [];
    }
    groupedByFolder[folder].push(file);
});

// Display folders and links to canvases
for (const folder in groupedByFolder) {
    dv.header(3, folder);  // Folder name as a level 3 header
    dv.list(groupedByFolder[folder].map(file => dv.fileLink(file.path)));
}

I also figured out how to display both md files and canvas, so here it is

// Get all files with .md and .canvas extensions
const allFiles = app.vault.getFiles()
    .filter(file => file.extension === 'md' || file.extension === 'canvas')
    .sort((a, b) => a.name.localeCompare(b.name));

// Function to group files by folders
function groupByFolder(files) {
    const grouped = {};
    files.forEach(file => {
        const folder = file.path.split('/').slice(0, -1).join('/') || 'Root directory';
        if (!grouped[folder]) {
            grouped[folder] = [];
        }
        grouped[folder].push(file);
    });
    return grouped;
}

// Group all files (canvases and notes)
const groupedFiles = groupByFolder(allFiles);

// Display files by folder
for (const folder in groupedFiles) {
    dv.header(3, folder);  // Folder name as a level 3 header
    dv.list(groupedFiles[folder].map(file => dv.fileLink(file.path)));
}

1 Like

and here is an alternative if all folders need to be displayed regardless of whether they contain notes or not

// Get all files with .md and .canvas extensions
const allFiles = app.vault.getFiles()
    .filter(file => file.extension === 'md' || file.extension === 'canvas')
    .sort((a, b) => a.name.localeCompare(b.name));

// Get all folders
const allFolders = new Set(app.vault.getAllLoadedFiles()
    .filter(file => file.path.includes('/'))
    .map(file => file.path.split('/').slice(0, -1).join('/')));

// Add the root directory
allFolders.add('Root directory');

// Function to group files by folder
function groupByFolder(files) {
    const grouped = {};
    allFolders.forEach(folder => {
        grouped[folder] = [];
    });
    files.forEach(file => {
        const folder = file.path.split('/').slice(0, -1).join('/') || 'Root directory';
        grouped[folder].push(file);
    });
    return grouped;
}

// Group all files (canvases and notes)
const groupedFiles = groupByFolder(allFiles);

// Display files by folder
for (const folder in groupedFiles) {
    dv.header(3, folder);  // Folder name as level 3 header
    if (groupedFiles[folder].length > 0) {
        dv.list(groupedFiles[folder].map(file => dv.fileLink(file.path)));
    } else {
        dv.paragraph("No files in this folder.");
    }
}

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