Bulk delete all notes inside a specific folder that do not contain a specifc tag

Is there a way to do it?
Just to make you understand, I need it because I would like to export Readwise highlights that match only a specific tag. But Readwise doesn’t offer this very symple functionality, so this would be the workaround. Let’s say I tag some highlights with #work: I would like to delete all the notes inside the Readwise folder that don’t contain the tag #work.

(I know that Readwise would create the deleted files again, but then I would delete them again. Obviously I would keep the Readwise sync on once per day. Let’s say I could delete them every time before I start working on highlights. Best would be to assign it to a hotkey)

I) Within Obsidian
Bulk Rename
I couldn’t figure out how to find “notes that don’t contain the tag #work”, so I focused on finding “notes that contain the tag #work” and moving them to a new subfolder.
your #work → my #-e-car-
I’m using the Tags option
after entering the tag always click on Preview @ the very bottom(not shown in screenshot)
First tried moving them from z_capture folder TO z_delete folder, I got a warning that I must first create a folder … so I needed first to create z_delete/glasp

It moved them correctly.
So I think you could adapt this to your needs.


II) Using Grep for your OS
Here I am using grepWin
Grep Search for -e-car-



Grep DELETE Inverse search results i.e. NOT containing -e-car-

1 Like

After export to Obsidian every note is a single file. Isn’t it?
Why don’t you just export all and do it in your system file manager. Just move content of exported folder to another folder, search for files that contain these tags and move search result again to original Obsidian location.

Because I need to do it every day, every time I sync Readwise. I would like to make it the less manual possible

I believe it is possible to write some script to do so and execute it on shortcut or make an icon for it. For example on Linux it should be trivial for some advanced users. But ask on some forum for your system or https://stackexchange.com/ or some similar forum.

You can use the Obsidian plugins Templater and Dataview for this.

  1. Create a template to execute manually or via a hotkey.
  2. In the template, find the list of notes using Dataview.
  3. Loop through each note and call app.vault.adapter.trashLocal(file.path) to safely delete the file and send to Obsidian trash.

Here’s a working template, just change “Some folder” to your actual folder. It will safely trash any file from that folder which doesn’t include the tag #work.

:rotating_light: Please take a backup of your vault first, or try it in a test vault.

const dv = app.plugins.plugins.dataview.api
dv.pages('"Some folder" AND -#work')
  .forEach(note => {

If you don’t want to run the template manually, you can put this Dataview code at the bottom of some note you frequently access, and every time you go into that note it will silently clean up the Readwise files:

dv.pages('"Some folder" AND -#work')
  .forEach(note => {

This is perfect!!! Precisely what I needed! Thank you so much!!!

1 Like

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