Replacing deleted attachments in Zotero's storage folder

Hello

Due to a snafu having nothing to do with Zotero, I accidentally deleted most of the file attachments (e.g., pdf files) from my Zotero storage directory. The directory structure is still there (consisting of names like DHE5ASNE), or at least a great deal of it is. But the files are mostly gone. (Fortunately, the .sqlite Zotero database itself seems to be ok.)

I managed to recover many of the pdf files with deleted file recovery software. My questions are about how I might manage to put them back where Zotero .

First of all, is there an easy (or at least automated) way of finding which attachments are not where Zotero expects to find them, other than just clicking on every one of them?

Second, is there a smart way of getting files back into their original folders? (I'm comfortable scripting, if it makes a difference.)

Thanks a lot for any help!

Malcolm
  • edited January 27, 2021
    First of all, is there an easy (or at least automated) way of finding which attachments are not where Zotero expects to find them, other than just clicking on every one of them?
    The "Attachments" (blue dot) column will show you whether files are present or missing:

    https://www.zotero.org/support/sorting
    Second, is there a smart way of getting files back into their original folders? (I'm comfortable scripting, if it makes a difference.)
    You're saying you have the files with their original names, but not connected in any way with the folders they were in?

    You could pretty easily write a Python or similar program to run an SQL query on zotero.sqlite (joining items and itemAttachments by itemID) to get the item key and filename for all attachments in your database with a path beginning with 'storage:', look for each filename in the temporary folder, and copy it to the associated storage directory if not already present.
  • Thank you, that is very helpful!

    Unfortunately, the files don't have their original names; rather they were renamed according to the title in their metadata by the file recovery program. It might still be possible to write a script that matches the titles in the Zotero database with these files but that depends on them having the same title in their metadata and in Zotero. There are only about 350 missing attachments, so I think it may be worth just adding them manually.
  • edited January 27, 2021
    Note that files that you've previously synced will be automatically downloaded when you try to open them. If you use "at sync time" file sync mode, you can also use Reset File Sync History from the Sync → Reset pane of the preferences to force it to redownload all missing files (though I think currently you might need to add a file on another computer or the web library to trigger the download).

    But you're at your file sync quota, so presumably you have a bunch of files that weren't uploaded because of that.
Sign In or Register to comment.