orphan attachments

Due to a backup error I copied deleted attachments/folders back to the 'storage' folder. Which means that the storage folder now holds attachments which should not exists. Since I do not know the names/dates of these attachments/folders, I cannot remove these orphan files/folders.
Is there a solution for this issue?
thank you
  • No current solution. It's possible there's a third-party plugin or script that will do this, but nothing built-in. We'll probably add something like this at some point (along with functionality to remove synced, downloaded attachments after a period of time) — issue created to track it.
  • (pretty sure there's a perl script floating around on the forums. I think posted by mronkko originally)
  • edited October 7, 2016
    I remember mikko's solution about that : https://forums.zotero.org/discussion/comment/107163/#Comment_107163

    [Edit: sorry, exactly what adamsmith and bwiernik had in mind…]
  • well, that thread also has a python script, so it's very useful to have, thanks
  • Thank you all. The Python works like a charm, great that it reveals the orphans first instead of immediately removing them.
  • edited November 8, 2016
    Did anyone manage this in Windows? I've tried both the perl and the revised python script with no success.

    The python script gave me a readout:
    XX attachments
    YY files
    XX missing attachments
    YY unattached files

    Where the same values were listed for both pairs of XX and YY. Probably shouldn't be that way. And I'm not sure how to make it 'do' something.

    The perl script gives an error saying "unable to open database file" for the zotero.sqlite file even when firefox is closed.

    Am I doing something wrong?

    Any idea on how far away official support for this is? If its not too far off I'll just leave it, but otherwise I would like to try to remove all of my orphaned attachments.

    My use case is simply that I've deleted Zotero entries but the linked attachments (in my Google Drive folder) remain.
  • edited January 9, 2018
    I have a solution for removing orphaned attachments using Zotfile (which I've just successfully used). I'll explain here. First I would suggest correcting metadata that is used in renaming - this is a good opportunity to wipe the slate clean. Assuming the current directory of your files is \Documents\ZoteroOld

    1. Set Zotfile directory to a new temporary location e.g. \Documents\ZoteroTemp.
    2. Highlight everything in your library > right click > manage attachments > rename attachments.

    All attachments get moved to the temporary directory. Will take a while for large libraries.

    Now simply delete the entire folder where everything was just moved from (\Documents\ZoteroOld). The orphans are gone.

    3. Create a new directory for where you want your attachments to go, for example \Documents\ZoteroNew - Or it can be the same as what you just deleted.
    4. Change the directory back to this new directory in Zotfile preferences.
    5. Highlight all and and rename attachments as before.

    Now everything is moved back. All files in that folder are now linked, and all the orphans are gone.

    Really quite simple, ZotFile is such a handy tool.

    Remember to back up your attachment directory beforehand just in case.

  • I'm on a Mac, no "manage attachments" option shows up. Is it available on another menu? I tried various places (and key combinations) without success.

    The underlying issue is that when I look for a pdf, I often find it's in Zotero twice, once linked to the proper bibliographic entry, once orphaned / apparently unlinked.
  • @msmitka The above solution requires you to be running the ZotFile extension (http://zotfile.com/)
  • OK – thanks!! – that works so far. However, I also have many entries without attachments. So I will play around cautiously to make sure I don't delete those entries. I suspect it's in the various notes to Zotfile, I'll post again with success (or perhaps) continued issues. But as noted, it will take awhile to move 1800 files.
  • You could always backup your attachment directory before hand just in case.
  • Before correcting my orphaned file issues (i.e. - renaming an orphan by whatever means), I use a duplicate file search (Mac Os X - Duplicate File Finder) to locate and isolate duplicates as they have some root name commonalities. Renaming removes the easiest route to duplicate identification. It may still be possible based on file size or some other metric, but you must then engage in the teduim of verifying, often by viewing each file. I repeat the duplicate search after batch renaming. I have no explanation of a mechanism, but I have found duplicates.
  • edited 19 days ago
    @Tsau017 you are a genius! Thank you for sharing this tip!
  • Thanks @tychen742, glad you found it useful!
Sign In or Register to comment.