Things I have tried
I found a post here that talks about a possible way to find PDFs using DataviewJS, but I couldn’t get it to work.
What I’m trying to do
Basically I’m scanning in my son’s homework from Kindergarten and placing them in a folder called “Scans” in his “Kindergarten” folder. I have a note called Kindergarten+ (I add plusses to all my dashboards like I’m a streaming service for some reason, lol) and I’ve been manually linking to his scans.
I’d rather just run a quick dataview code that can just list everything from his Scans folder by created time.
Anyone got a way to do that?
What doesn’t work in particular? Filter the folder?
Can you give some more information how exactly your (failed) code looks like?
Besides that, if all pdfs reside in just one folder and this folder only contains the files you want to list, some simple query like this should probably work:
TABLE file.ctime AS created
SORT file.ctime DESC
The point is: Dataview works only with md files.
(ignoring the particular case of csv files)
Then my solution probably shouldn’t work…
Actually, I haven’t thought about this as I never needed to list non-md files myself…
Sure, here’s what my code looks like:
const pdfFiles = app.vault.getFiles().filter(file => file.extension === 'pdf' && file.path.includes('11 - 👦🏻 Finn/Kindergarten/Scans')) dv.list(pdfFiles.map(file => dv.fileLink(file.path)))
And here’s what I get back:
Evaluation Error: SyntaxError: Unexpected identifier
at DataviewInlineApi.eval (plugin:dataview:19669:21)
at evalInContext (plugin:dataview:19670:7)
at asyncEvalInContext (plugin:dataview:19680:32)
at DataviewJSRenderer.render (plugin:dataview:19701:19)
at DataviewJSRenderer.onload (plugin:dataview:19285:14)
at DataviewJSRenderer.e.load (app://obsidian.md/app.js:1:852538)
at t.e.addChild (app://obsidian.md/app.js:1:852939)
at t.addChild (app://obsidian.md/app.js:1:1242194)
at Object.addChild (app://obsidian.md/app.js:1:1241219)
at DataviewApi.executeJs (plugin:dataview:20210:19)
- if you want only one line you need to separate the different parts of the code with the
const pdfFiles = app.vault.getFiles().filter(file => file.extension === 'pdf' && file.path.includes('11 - 👦🏻 Finn/Kindergarten/Scans')); dv.list(pdfFiles.map(file => dv.fileLink(file.path)))
- if not, you need at least to break the line:
const pdfFiles = app.vault.getFiles().filter(file => file.extension === 'pdf' && file.path.includes('11 - 👦🏻 Finn/Kindergarten/Scans'))
dv.list(pdfFiles.map(file => dv.fileLink(file.path)))
(I’m not versed in JS, but I guess it’s something like what I said )
More problematic will be the sort thing… because you can’t use the
And play with dates inside JS is (at least for me, a js dumb) a painful thing.
So it literally worked by adding the line break. I thought it was in there, but it was just a wrap. I added the line break and it worked.
What is the dataviewjs command for sorting it by created time?
Oh I just saw your other comment about the file.ctime. I’ll check and see how to do that.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.