Zotfile does not delete PDF files when a database entry is deleted

Hi,
I have zotfile set with a custom location for the PDFs.
I've noticed that zotfile won't delete the PDFs after moving an entry to trash in zotero, not even after emptying the trash.

Essentially unwanted files just accumulate in my PDf folder without ever being removed automatically.

Is this a known bug?
Any workarounds?

Thanks!
  • I don't provide support for ZotFile (and someone can correct me if I'm wrong), but as far as I know it just creates regular Zotero linked file attachments, which are stored in the Zotero database, and doesn't do anything with the attachments after that. Once those are created, the rest is all Zotero, and Zotero doesn't delete linked files when you delete the items from Zotero, because the whole point of linked files is that the files themselves aren't managed by Zotero.

    I think maybe that answers your other question as well?
  • (Which isn't to say that ZotFile couldn't watch for deletions and delete the linked files as an optional feature, but that's not something we do in Zotero, since the thought of deleting users' files outside the Zotero data directory scares us a bit.)
  • Hmm, not sure I understand you.
    Without zotfile, adding an entry to the DB creates a subfolder under `storage` with some obscure code and in it the pdf file is stored. Deleting the entry makes zotero delete the subfolder.
    Using zotfile, the subfolder is created but the pdf is subsequently moved to the custom storage location and the subfolder is left *empty* (i.e. no link is formed). Deleting the entry in zotero has no effect on the pdf file in the custom location.

    This seems to me like bugs in zotfile, no?!
  • edited October 14, 2014
    No, you're confused. There are two types of file attachments in Zotero proper, linked attachments and stored attachments. ZotFile just provides some features that can make working with linked attachments easier.

    https://www.zotero.org/support/attaching_files#file_copies_and_links
  • I do understand the difference. So what you're saying is that zotfile is only responsible of turning zotero's stored attachment to a linked attachment, and the fact that zotero doesn't delete the linked file (or gives an option to do that) is a zotero bug.
    Did I get you right?
  • Not quite. The fact that Zotero doesn't delete the linked files when you delete the items is a feature. It's entirely on purpose and will remain so. That's generally how links work, in Zotero and beyond.

    There's, however, an open ticket in ZotFile that would allow you to get this or similar functionality. Absent 3rd party work, it's not likely to get implemented, though:
    https://github.com/jlegewie/zotfile/issues/96
  • Thanks adamsmith,
    You're absolutely right that typically targets should not be deleted when links are, but in this case there are oblivious problems created.
    Thanks for the link on the ticket, I hope at least someone will come up with a workaround...
  • But this is absurd... the result is that you end up with duplicated pdf files.
  • edited July 23, 2016
    Workaround suggestion:

    Clean up by changing the custom location of files, and the 'clutter' remains behind. As follows:

    1) Create new custom folder:

    Tools --> Extensions --> Zotfile Settings --> Change 'Location of Files' --> Create and select new folder (I named it with a date tag)

    2) Copy Zotero library to new custom folder:

    Select all entries in 'My library' (e.g. CTRL+A) --> right click for menu --> Manage attachments --> Rename Attachements --> Accept 'Do you want to move and rename attachments?"

    3) Double check and delete/archive the outdated Zotfile folder

    I've just installed Zotero+Zotfile, but this seems to be working (had to migrate a bunch of refs)

    Cheers!
  • edited November 2, 2016
    I wish zotero would be like iTune with a "library folder", where I have a clear folder where files are organised and managed by zotero.

    This is important for one who want to access research papers with other tools like devonthink, spotlight, ...

    zotfile is a ugly workaround.
  • @gagarine, your best bet would be to store files outside of Zotero and use the "Link to File" option to attach the files to items in Zotero. I use that method and have found it to be the cleanest way to manage my burgeoning PDFs, while keeping my Zotero database small. You can place the files in a cloud synced folder such as OneDrive or Google Drive. Do NOT keep your Zotero database folder inside a cloud synced folder. So, basically, let Zotero sync the metadata and the cloud service sync the actual files.
  • @gurdas thanks, it's what I'm doing with the help of zotfile. But I'm looking for good default... not workaround ;). I really thinks it's what making a good program: it works out of the box.
  • Hey Guys, this is a very late comment, but I just made a python module to help with this. You can use it to clean up files from your filesystem after removing them from zotero or add new files to your zotero after adding them to the zotfiles directory.

    Check it out at https://github.com/j718/zotero-sync
  • edited September 10, 2020
    There might be a workaround.

    1. First it is assumed nothing important is lying in :Unfiled Items: to begin with.
    2. A new collection titled :DELETE: is created.
    3. Zotfile is needed to rename & relocate the linked attachments via a subfolder scheme defined by :%c: (This could be done/ changed temporarily just as well for this purpose).

    4. The item to be deleted is removed from its parent collection, and now comes to lie in :Unfiled Items:.
    5. Once in a while all items in :Unfiled Items: are moved to the :DELETE: collection, followed by a Zotfile rename command that relocates the linked files to the :DELETE: folder within the Zotero storage directory.
    6. The items are now moved to the bin & deleted permanently.
    7. Once items are deleted from Zotero, their defunct attachments are similarly wiped out from the :DELETE: folder.

    8. The Zotfile rename preferences maybe changed/ removed as before

    Thanks to the devs for an amazing piece of work! Thanks also to the lively Zotero community!!
  • edited May 2, 2022
    I've just found another workaround (inspired from @jonasagerbæk answer).
    I'm on linux:
    - File -> export library (with export files option) to any dir. Say ~/A.
    - Copy all files to a directory:
    cd ~/A && mkdir pdfs
    find files/ -type f -exec cp '{}' pdfs/ \;
    - List the files to delete:
    rsync -van --delete pdfs/ zotfile-dir/
    - If this list of files is correct, delete them by removing the -n

    This only works if, like me, you have all pdf managed by zotfile all dumped in a dir.
    This is just an idea. Modify as you need.

    @j718 I prefer to manually watch what is to delete, but thanks. Nice work!
  • My workaround for this is to have a tag named Delete and have assigned #1 color priority to it, so that it gets labeled when I press 1.

    Then I can periodically filter for that Tag, bulk "Convert Linked Files to Stored Files", then select all and Move to Trash, and empty trash.

    This seems pretty smooth and doesn't need to use any fancy scripts or anything.
  • I just had this exact problem, what I did was:

    1.- Set a new custom folder in zotfile preferences and rename all attachments.
    2.- Erase all files in the old custom folder
    3.- Set the old custom folder in zotfile preferences and rename all attachments (optional).
  • Alternative by @johnmy using "Tools > Developer > Run JavaScript" functionality of Zotero:

    Code: https://github.com/redleafnew/zotero-javascripts/blob/main/04delete-the-attachment-files-after-the-items-have-been-removed-when-zotfile-was-installed.js


    Just comment the following line to test the behavior:
    await OS.File.remove(FullPath); //删除文件

    Source: https://zhuanlan.zhihu.com/p/356071795 (Chinese)
  • Another postscript to this old thread: the delitem plugin can now delete the linked PDF attachment when an item is deleted. There is a version for Zotero v6 (0.1.06) and the latest version for the Zotero v7 beta.
    https://github.com/redleafnew/delitemwithatt
Sign In or Register to comment.