Can't zotfile delete attachment?

When I delete a reference, I want to delete the index listed in zotero, and delete the attachment as well to release some space for new attachment. However, when a reference is "renamed" by zotfile, the reference attachment comes to a link. Then, when a delete a reference, the attachment is still there. So I think there must so many useless attachement in my hard disk now.
So, the question is, how to deal with it? Did I set some thing wrong?
  • Zotero doesn't delete linked files, only stored files, since it doesn't have any way of knowing if you're using the file outside of Zotero. If you want Zotero to manage files for you, you need to use stored files.
  • Well, I think this should be the function of zotfile.
  • It can add attachment, it should delete the attachment as well.
  • ZotFile makes it easier to use linked-file attachments, but linked-file attachments are just a standard part of Zotero. Deletion is handled by Zotero, not ZotFile.
  • What I mean is there must be a connection between the links and the linked-file attachments. This link is made by zotfile and should be recognized by zotfile. So if the link is deleted, zotfile should tell that and delete the corresponding attachment. So, what zotero deleted is only the index and the link (this storaged in the storage folder of zotero), but the attachement should be cleared out as well, this should be done by zorfile. Otherwise, the useless attachments will get more and more. Apparently, zotfile has no this function right now.
  • I think you're still misunderstanding the technical part of this. There's absolutely no difference between a linked file that you create manually in Zotero and one that ZotFile creates for you. ZotFile doesn't keep track of those, and it would require major changes to do so.

    Any plugin, ZotFile included, could in theory alter Zotero's deletion behavior for linked-file attachments to delete the associated files, but that doesn't really have much to do with ZotFile's current functionality, which is simply to make it easier to create the same linked-file attachments that you can create yourself.

    In any case, that would be a feature request for the ZotFile developer.
  • Whatever I am thinking, the result is that zotfile moved the attachment from the fold of "stotage" to another, and then the attachment can't be deleted if you delete a reference in zotero. This is not zotero's fualt, because the attachment has been moved, and this is not zotfile’s fualt, because zotfile only to change the location of a attachment and make it easier to creat the link.
    Then, if you want to delete a reference, you should delete the attachment first. Or, just change to use another?
  • @liuhaijin I think you just have to accept that linked files will not be deleted by Zotero currently. For pros and cons, see e.g.:

    https://forums.zotero.org/discussion/79899/deleting-removing-item-should-remove-ask-to-remove-any-attachments

    You could consider using stored files instead:

    https://forums.zotero.org/discussion/79437/pros-and-cons-of-attach-link-to-file-vs-attach-stored-copy-of-file

    As a workaround, you could convert linked files to stored files prior to moving ítems to trash:

    1. "File"/"Tools" -> "Manage Attachments" -> "Convert Linked Files to Stored Files"

    2. "Move Item(s) to Trash"
  • @qqbb Thank you. This is a way. I have used zotero for 5 years and this is the only problem I want to say. Because my reference folder is getting larger and larger. I agree with that zotero has no defect on this point, only zotfile should improve the performance. However, zotfile may be not developed by zotero.
    I can reorganize the reference with the method you provided. In case of some other people raised this problem, it should be resolved sooner or later.
    Thank you again.
  • edited November 29, 2019
    Dan, how about having a user-preference setting that tells Zotero to delete (or not) the attachment, too, when the parent item is deleted?
  • 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.
  • @Gurdas_Sandhu, it is a good idea.

    I coded a JS to clean the customized reference fold after Zotfile is installed, https://github.com/redleafnew/zotero-javascripts/blob/main/4delete the attachment files after the items have been removed when zotfile was installed.js

    when batch deleting needed, https://github.com/redleafnew/zotero-javascripts/blob/main/5delete the addachments when the items were removed.js could be used.

    An context menu add-on has been developed, but function not well.
  • @johnmy those look cool. How do we use them? Copy them one at a time and run the code? Or can they be saved within a menu item by an addon?
  • Yes, when you delete item(s), select it (them), and run the JS in the JavaScript window (Tools- Developer-Run javascript). I developed an addon https://github.com/redleafnew/delitemwithatt/releases, but it is not a finished product, it will jump (slip, swaying, I don't know how to describe the phenomenon) when the context menu was activated, and sometimes it does not work, which I have no idea to debug it.
  • As a very crude workaround, I used Zotfile to rename all attachments in my library using modified renaming rules, simply appending "1" to the beginning of the file name. Then, in the linked storage folder, I just sorted by filename and deleted anything that didn't start with "1". Finally I repeated the rename command with the original renaming rules.
  • I modified the addon https://github.com/redleafnew/delitemwithatt/releases, when you delete an item, you can right click the item and select delete attachment , then you can choose delete the attachments or the items, the stored files would be put the zotero trash and the linked files would be removed from the disk directory (CAUTION!).
  • edited November 4, 2021
    @johnmy, this is great, thank you! do you think there is a way to safely move the attachment to the system (not Zotero). recycle bin, instead of deleting it permanently? Even with your CAUTION this seems like a very dangerous function at the moment.
  • https://groups.google.com/g/zotero-dev/c/cU-6O8cCWsg
    I am trying to find this type of function, but not available.
Sign In or Register to comment.