Dataview - List all canvas files in specific folder

Hi Fellow Obsidian Friends,

Nothing really special, just a snippet that might help other folks working on their own custom folder structures, project homepages, and Dataview queries.

I found a similar topic (list all canvas files), but what I needed was specifically listing all canvas files from a specific folder.

It took me an hour to make Dataview’s dataviewjs query type do what I asked:

```dataviewjs
const moodFolderFiles = app.vault.getFiles()
	.filter( (file) => { 
		return ( 
			file.path.includes('MOODBOARDS') &&
			file.path.includes('.canvas')
		) 
	})
	.map( (file) => {
		const matches = file.name.match(/([^/]+)\.canvas$/)
		return dv.fileLink(file.name, false, (matches ? matches[1] : file.name))
   });

dv.list(dv.array(moodFolderFiles).sort(l => l.display, 'desc'));
```

If you have some ideas, suggestions on improving the snippet, I welcome all shares.

3 Likes

Thank you. Bewen bugging me for a while. Worked a treat.

1 Like

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

here’s an alternative