I created my Vault from my Apple Notes database. I had over 30,000 Notes in the database, including over 21k images.
All of these images were placed in the root folder of my Vault. This makes it hard to locate any one image, and makes it slow to work within that folder (for obvious reasons).
What I’m trying to do
I would like to relocate all the images to _resource folders in the same folder as the note that includes those images. I understand this will take some sort of batch processing, including moving files in the Finder and updating the paths in the note itself.
I installed Obsidian Local Images Plus by Sergei Korneev from the Community plugins, because I thought it could do this, but I haven’t been able to get it to process the currently existing notes (or notes I create on my iPhone or iPad).
I have tried running the commands given in the plug-in’s documentation on the command-line, to the best of my ability, but haven’t been able to make it work.
I was hoping somebody could help me figure out the correct commands, or point me towards another plug-in that can do this.
Can you show an example of the format of the image links?
Do the images have unique names?
By default in Obsidian, if you were to manually add an image - and if you have “Shortest link possible” in your links settings, then the path doesn’t matter.
So alternatively, if you can find a way to restructure your links so they just point [[imageName.png]] then you can freely move the images without breaking the links. If the links are already in that format, you might be good to go already.
None of that might help you directly with the folder sorting you want to do. But maybe some of those ideas give you new options while you’re searching for tools or scripts to help/
(I suggest backing up before doing any batch processes or major restructuring.)
The issue is moving to separate resource folders based on each source note.
Although you are right, if that was the first step, it would fix the initial performance issue of having them all in the root folder, until a better sorting tool can be found or scripted.
This is not a full-blown solution, but more of an idea on how I would approach this, and that is to actually use Templater to run a dedicated script to move some files, maybe a 100 files in one go for starters, and then repeatedly run that script, possibly increasing the number when you start to feel confident it does the right thing.
The template would do the following:
Use dataview to locate roughly 100 files having image links in their file.outlinks list, and return this list of files to the Templater script
Loop on each of those images, and use tp.file.move to move the actual file to the correct sub-folder of the current file. This will ensure that Obsidian updates it cache and whatnot, so the file is properly moved, and links updated if so needed. (It might be needed to keep track of which files we’ve moved already in the current batch, so as not to move the same file multiple times)
In any case, we should also log the state of the move operation, and any other potential error messages, and keep these log files somewhere so that we can re-iterate if something goes astray at any point
I’m not at liberty to actually write out such a script just now, as I’m rather low on energy and time, but I just wanted to present the gist of it, so as to indicate that it should be doable given a little time and coding knowledge.