Using DataviewJs to extract a list of recently uploaded images in the vault from the attachment folder

What I’m trying to do

  • I have a fixed folder / path in my vault where all the attachments go by default.
  • Sometimes, I accidentally paste something in my note, and instead of copied text or link, I paste previously copied file instead to the note. As a result, the file immediately is added to the default attachment path.
  • Now I want to remove that upload from the vault. However, I will have to search through the attachment folder to identify and find which recent image or other type of file was uploaded by me.
  • I want to create a dataviewjs (as dataview cannot do this) query that will identify and find X recent files from the specified attachment folder and list them down (along with hyperlinks) along with their file name, file type, and upload date in descending order.

How to do this?

Path: “Dump/Resources/Attachment”
Limit: 10 recent files
File type: Any.

Something like this?

```dataviewjs
const folderPath = "Dump/Resources/Attachment";
const limit = 10;

const files = app.vault.getFiles()
    .filter(f => f.path.startsWith(folderPath + "/"))
    .sort((a, b) => b.stat.ctime - a.stat.ctime)
    .slice(0, limit);

dv.table(
    ["File", "Type", "Created"],
    files.map(f => [
        dv.fileLink(f.path, false, f.name),
        f.extension,
        new Date(f.stat.ctime).toLocaleString()
    ])
);
```

This will get you something like this …

Cheers, Marko :nerd_face: