Best way to clean up collection.media?

Hi there,

I’ve got clean over 2k images saved in my AppData/Roaming/Anki2/<username>collection.media directory, as a result of downloading various Anki decks. Looking through it this morning, I’m seeing that the majority of the image files don’t follow any particular naming convention, which makes it a real pain to hop in and make any edits (e.g. removing OREGON from the Oregon state flag makes it a more substantial flash card).

I found that in Windows, you can shift-click a section of cards, then while still holding shift, right-click -> rename, and if you type a prefix on one of the files, it applies to all of them. Super cool feature I didn’t know existed in my decade+ of using a PC.

However, having done this, now all of the references to my cards are (understandably) broken. Went back and CTRL+Z’d my way out of the hole I dug, but now I’m here asking if anyone has any pointers for how I might go about renaming my media collection without manually updating the references on a couple thousand cards.

Thanks!

Anki has a Find and Replace feature you can use to change media references in your notes. If some of your images follow a particular pattern, this can be useful.

For images that don’t follow a pattern, then there is no magical solution (though I think it’s easy to write an add-on to change filenames and references in a way that keeps them functional).

If you really care about filenames, maybe rename each file and its references incrementally when you review cards containing them.

3 Likes

Hey, yeah. I think this is the route I bound to go, save for some add-on I might have been missing.

Appreciate the response!

For renaming images there is dedicated software for Windows, ReNamer for example.
You can export cards and find and replace in Excel or any other spreadsheet program gives you plenty of possibilities.

Also you can put some image files in folders that are within collection.media but you will have to adjust paths in Anki. But this can be easily done with Find & Replace in Anki browser.

<img src="folder_name/112.png">

I think “Treat input as regular expression” must be active in Find & Replace in Anki browser.

I would not recommend using subfolders, and they are not supported by the media check or syncing.

1 Like