Remove unused attachments

Hi everyone! Has this just been dropped suddenly? Or is it implemented and I have not found it? I am only starting with Obsidian now, but can already tell that my attachments folder will be a huge mess if this is not available. Specifically when dragging a lot of screenshots into the notes, that usually do not have names suggesting their content.

1 Like

This is an open feature request.

Above, you’ll see a workaround using a plugin. (I haven’t tested it personally.) Remove unused attachments - #7 by Vinadon

5 Likes

Thanks for the quick reply! @rigmarole I’ll check out the third party plugin then.

There’s also a new plugin called Janitor that does this (and other things)

7 Likes

I’ll check on the suggested plugins after I made progress on post import cleanup from Evernote.

My attachments folder currently has over 18k files in it. After I remove notes that whose only content was an attachment (think, pdf document) , I’ll run a plugin and see how many it cleans up.

This feature works be a great core feature imho. Maintaining a file reference count and deleting the file when the count hits 0 isn’t a small task, though.

1 Like

Perhaps it’s better to move those files in a folder ā€œattachments_not_in_useā€ instead of more or less blindly delete them.

1 Like

A temp location could be handy in case you restore a note that you deleted by accident. or we can say that the used is responsible for restoring it from the ā€œtrashā€ folder or from backup.

ie
User deletes last note that references an attachment.
Obsidian deletes attachment
User restores note
attachment link is now broken.

Totally agree with the need of an ā€œautomatic removalā€ of attachments after a note was deleted. It is painful to do this manually and really a bummer when using the app with attachments. Please add something that takes care of this.

3 Likes

If you read the thread, there are plugins that do this.

1 Like

I use this plugins called nuke orphans btw

čæ™äøŖę‰©å±•éžåøøę£’
This extension is great!

Use case or problem

I would like that if I delete a note, I would be asked what to do with the documents linked in it, if they have no other references, whether to keep them or delete them.

Proposed solution

When I delete a note I would like that if there are linked media that are only in that note, I would be asked whether to keep them or delete them

Current workaround (optional)

All files remain

1 Like

Hi everybody!

DON’T EVER USE SHITTY PLUGINS FOR FILE CLEANING, THEY WILL ERASE EVERYTHING THAT DOESN’T NAILED TO YOUR DOCKS, AND YOU CAN’T THAN RESTORE THE STRUCTURE!

THE MOST UGLY SOLUTIAN AS IT CAN BE. I LOST ALL MY ATTACHMENTS :cry:

In details:

  • They just move files to bin, and you can’t restore them from bin to their previous location. You can get them as a huge of files and thats all you can do.
  • They will not ask you about DO YOU REALLY WANT TO DO THIS HORRIBLE THING!
  • The even will not show you the list of this files…

You just lose everything.

1 Like

This is why when you activate plugins you agree to the risk. It makes the suggestion that you backup your work. Even without plugins, it’s a very good idea to make backups for any important data.

I’m sorry you lost some work, and I know that’s probably not what you want to hear right after losing some work.

Keep backups! Always.

And other suggestions are to use version control such as Git. And to use a test vault when you’re testing out new plugins.

1 Like

You can do local backups.
You can do backups in Dropbox/ GDrive/ Onedrive / Git.
Familiarize yourself with how plugins work and make sure you configure them correctly.
If you combined different plugins, there is a risk things don’t go well e.g. plugin to clean orphan attachments automatically can run havoc with another plugin offering same or similar functionality or unrelated functionality e.g. plugin to move attachments or plugin to sync attachments (which also can delete attachments). So you have 2 plugins, one deleting when doing sync, another plugin handling orphan attachments… this can cause data loss.

That’s why important to configure plugins conservatively at most so you preserve control.

If you have important content you can’t lose, I would suggest look for other options such as Joplin which also has plugins but they are non-destructive, meaning they handle add-on function on Joplin. The core function such as maintaining notes and attachments is handled by Joplin directly.

You do have the option to export your notes in MD format if you need.

–
That’s why I would stress the importance of this:

Obsidian should handle destructive functions as part of the core application, and not rely on 3rd party plugins:

1. creating notes
2. renaming notes
3. moving notes
4. deleting notes
5. moving attachments (have flexibility, root folder, note folder, subfolder in attachment folder etc…)
6. renaming attachments (e.g. rename attachment to match the note name, unique attachment names…)
7. deleting attachments (orphans)

**If note is moved to another notebook folder, the attachment would be moved accordingly e.g. **

Example:

Vault / Notebook name / Note123.md

Vault / Notebook name / .attachments / Note123 / Note123.PDF (attachment)

I know there are other people managing things differently, in any case, it would be crucial to have these functions part of Obsidian because that would likely prevent some if not all issues like this one.

3 Likes

I wanted to edit my post and I can’t edit anynore … here is what I wanted to add:

If note moves from Notebook Name to another notebook folder, both the note and the attachment can move.

If I add a new attachment to the note, the new attachment will be copied into the correct location Vault / Notebook name / .attachments / Note123 / …

The reason I have a number of plugins installed is because how weak Obsidian is when it comes with attachment management and how much time it takes to solve the orphan files issues. If I let the plugins to clean the issues for me, I risk losing data relying on 3rd party plugin.

This is not an optimal situation.

2 Likes

Well, this would be useful!

Temporary solution

Please add command:
Delete current file with "lonely" attachments
ā€œlonelyā€ - unused in another notes.

This sounds like a useful feature that should be implemented natively. People say plugins are unreliable in this regard, and cleaning files up manually can get annoying and tiresome.

2 Likes

Another use case is moving notes between vault. To my knowledge, you can open a parent folder to other vaults as a vault, and move notes between vaults that way. However, the parent vault has no way of know which subfolder(s) is the ā€œattachmentsā€ folder and will likely not move the file.

So then you have attachments in vault A that link to a file in vault B.