Deleting pdfs with no link to references

Storing and deleting pdfs
Hello,
I have deleted several references from my Zotero database and therefore several linked pdfs.

However, the pdfs I had retrieved (and now deleted) are still stored on my computer.

How can I identify the pdfs that are not linked to any record in Zotero?

Thanks for your help

  • edited 9 days ago
    To be clear, you do mean linked PDF attachment files not PDF files in local Zotero storage (under Zotero\storage), correct ?
    (sometimes people use the term 'linked' file ambiguously - it has a specific meaning in Zotero)

    When you move a Zotero item to the trash, Zotero only moves the item's PDF attachment file(s) to the trash if they are in local Zotero storage. It doesn't do that for linked attachment files (in a folder somewhere else in your OS). So ideally you need to delete the item and attachment in Zotero with the delitemwithatt plugin - that prevents the problem of 'orphaned' linked attachment files from occurring.
    https://github.com/redleafnew/delitemwithatt

    But if you *already* have orphaned linked PDFs still on your computer, finding them is a little difficult (particularly if you have a lot of them). Because you want to find PDFs on your computer that Zotero no longer has any record of. So by definition any code run within Zotero cannot completely address the problem. If however the items are still in the trash you may be able to identify the linked PDFs that still need to be deleted from their items there; and then delete them manually in your OS.

    But the following code run in Tools\Developer\Run Javascript will at least give you a list of all linked attachment files that Zotero *does* know about - that is, those that are still linked to current Zotero items. If you have a Linked Attachment Base Directory setting, the path for each file will have an 'attachments:' prefix in the list - replace that prefix with the LABD folder to get the actual full path to the attachment file on your computer.

    var filepathnames = await Zotero.DB.columnQueryAsync('SELECT path AS filepathnames FROM itemAttachments WHERE path IS NOT NULL AND path NOT LIKE ? ORDER BY path','storage:%');
    return filepathnames.join('\n');

    You can then compare that list to a list of all the attachment files in your linked attachments folder in your OS (a good reason to keep linked PDFs in a single folder). Those PDFs that are in that folder but not in Zotero's list are the orphaned files, that can be deleted.

    You say you only have 'several' orphaned PDF files, but whether you can easily manually find and delete the orphaned files depends on the size of those lists. Anything more than small lists and it will be best to write some code to do the comparisons and write a list of all the orphaned PDFs (and maybe do the deletions too). File comparison utilities may also help (to compare the two lists saved to two different files).

  • Thank you very much for your answer.
Sign In or Register to comment.