Fix broken pdf links where underscores are taken as blanks
Hello,
At some point during an upgrade of zotero and a migration to a new computer, I ended up with a lot of broken pdf links. Specifically, my new zotero installation believes that the files should be stored under a name like this:
.../zotero/storage/JJVPWVTT/Slonczewski - 1968 - Induced anisotropy in Ni-Fe films.pdf
However, in reality, the file is stored like this:
.../zotero/storage/JJVPWVTT/Slonczewski_-_1968_-_Induced_anisotropy_in_Ni-Fe_films.pdf
Essentially, the stored filename has underscores while the database entry has blanks.
I have been using zotero for quite a while since this happend and manually re-created the links to those papers that I use most often. However, there are too many to fix it all manually. Now that I have both, files with blanks and files underscores, is there any way to batch-fix these broken links? Ideally with a batch process that checks for every pdf if in my database if the link is valid and if not, replaces blanks by underscores in the database entry.
Thanks!
At some point during an upgrade of zotero and a migration to a new computer, I ended up with a lot of broken pdf links. Specifically, my new zotero installation believes that the files should be stored under a name like this:
.../zotero/storage/JJVPWVTT/Slonczewski - 1968 - Induced anisotropy in Ni-Fe films.pdf
However, in reality, the file is stored like this:
.../zotero/storage/JJVPWVTT/Slonczewski_-_1968_-_Induced_anisotropy_in_Ni-Fe_films.pdf
Essentially, the stored filename has underscores while the database entry has blanks.
I have been using zotero for quite a while since this happend and manually re-created the links to those papers that I use most often. However, there are too many to fix it all manually. Now that I have both, files with blanks and files underscores, is there any way to batch-fix these broken links? Ideally with a batch process that checks for every pdf if in my database if the link is valid and if not, replaces blanks by underscores in the database entry.
Thanks!
* the filename has underscores and the database entry does too
* the filename has underscores and the database entry has blanks
* the filename has blanks and so does the database entry
I'm happy to batch-rename with whichever software but it needs to read the zotero database to fix these links.
Thanks.
Even if you were going to use a script, the easiest script to write would simply check all attachments and, for any that were missing, check for another PDF in the directory and update the filename in the database to match. Something that went back and forth comparing database entries to files would be much more complicated. So batch-renaming the files to the desired form would be the first step regardless.
Is there a way to read the zotero database (or at least the file links) with python?
The alternative would be to do what I say above: 1) batch rename the files using an external tool and 2) use the JavaScript API in the Run JavaScript window to update missing stored-file attachments based on the single file in the directory. Writing that script without knowledge of Zotero internals would be tough, though.
Zotero.Attachments.LINK_MODE_LINKED_FILE
withZotero.Attachments.LINK_MODE_IMPORTED_FILE
in the relevant Zutilo code might work.should work (absolutely do _not_ use the "Replace online library" option, though)