Half of all attached files cannot be renamed properly -- appending old name to new name

I have a strange bug that has demolished half my library's attachments. It has made it such that half the files no longer have their extensions (e.g., .pdf or .xlsx), only the title. This made it such that Windows didn't know what the filetype was and you'd have to manually specify what to open it with -- unless you manually added back in ".pdf" to the end of the title, which would fix the issue.

This happened when I refreshed my attachment names according to my rules in Zotfile (attachment title = citation key, which is formulated by Better BibTeX) using Zotero 6. I tried to look into the bug via the Zotfile Github but found that it was deprecated and that I should update to Zotero 7. I did that on my other machine in case it posed a problem. Synced everything over to Zotero 7, and used its new renaming functions to set my files to be renamed in the same way as they were in Zotfile (using "{{citationKey}}" for the same effect).

Now, no matter what I do, whether I try to set Zotero 7 on one machine to use {{citationKey}} or whether I use Zotfile in Zotero 6 on another machine to rename the attachments, only one half of the attachment name is being changed. For example, it will change attachments to "citationkey. - yyyy - title".

For example, this citation's citation key is "Advanietal2021app". Using either method of renaming trying to rename it just to that citation key, it currently produces the following attachment name: "Advanietal2021app. - 2021 - The UK's wealth distribution and characteristics of high-wealth households online appendix". There is no extension, and Windows can't open it unless you specify what to open it with.

If I let Zotero 7 use its default naming scheme, the preview option says it will produce the following: "Advani et al. - 2021 - The UK's wealth distribution and characteristics of high-wealth households online appendix. - 2021 - The UK's wealth distribution and characteristics of high-wealth households online appendix". It just repeats it again, the last half of these citations are all stuck in some way.

I am completely at a loss as to what to do. My best guess is that something happened when I was using Zotfile on Zotero 6 earlier in the day, in the middle of it renaming all the files in the library (which I do to refresh everything, in case the citation keys have refreshed), I interrupted the process by exporting the collection to a .bib using Better BibTeX. Perhaps halfway through the process somehow the rest of them got corrupted or something, I don't know. I was trying to show a coworker the process of exporting my library and didn't think it would cause such an issue, but that's my best guess as to what could have changed.

Please help! Half my library is semi-borked, and this is a group library meant for an academic setting, so this is really really not ideal for our users. This is not just a personal library for me, in which case this would be annoying but the files are still technically usable.
  • edited October 5, 2024
    We can't speak for plugins, but Zotero itself should always keep an existing extension. It won't add an extension to a file that doesn't have it, though, so you'd have to fix those manually if they no longer have extensions. You can do that from the item pane after clicking on the attachment.

    Your example above is missing an extension altogether, but to clarify, for most of the ones in your library without extensions, it's something like this:
    Shorrocksetal2016.pdf. - 2016 - Global wealth databook 2016
    So that's a citation key plus ".pdf" followed by year and title. I don't know how you got that, but note that Citation Key isn't currently a field in Zotero except for the two new Dataset and Standard item types, so anything with a citation key is in the realm of plugins.
    If I let Zotero 7 use its default naming scheme, the preview option says it will produce the following: "Advani et al. - 2021 - The UK's wealth distribution and characteristics of high-wealth households online appendix. - 2021 - The UK's wealth distribution and characteristics of high-wealth households online appendix". It just repeats it again, the last half of these citations are all stuck in some way.
    Can you share a screenshot of the preview window showing that?
  • Yes, part of the problem here is that the extensions have somehow been deleted, and now Zotero isn't able to simply add the extensions back (even though Zotero 7 seems to be able to detect the file type and open them up appropriately if you double click them from within the application). If I could actually fully control the file name however (and not have this weird phantom second half that will never change), I could use Zotfile or anything else to force the file types back.

    I've already manually fixed the file extensions for the non-PDF files, which aren't as many. Then, for all the PDF files, I could selectively rename those with Zotfile to add ".pdf" to the ends of them. For those PDF files that already had ".pdf" I could then search for those, select just those, and then just rename them to the citation key again, which would keep the one normal ".pdf". I already tried doing this, and it worked...except for the files that had this stuff appended to the ends of their names. Which is how I got the file name you quoted above.

    That citation's filename was "Shorrocksetal2016", which is the citation key as generated by Better BibTeX. It was now missing its ".pdf" for some reason. Thus as described in the above paragraph, in my troubleshooting I renamed all PDF files to "%b.pdf" (%b = BibTeX citekey in Zotfile). I thought this would produce "Shorrocksetal2016.pdf" and that would be that, but somewhere along the way these bugged files had this other auto-generated stuff appended to their ends, and it won't go away for any of them. Thus "Shorrocksetal2016.pdf - 2016 - Global wealth databook 2016".

    Attached is a screenshot of the preview window showing what I'm talking about.
    https://s3.amazonaws.com/zotero.org/images/forums/u8719923/rqj4pf3krpcbr3smetwu.png
  • Also, I was under the impression that citation key is a field in Zotero that is usable for file renaming, per the documentation (https://www.zotero.org/support/file_renaming). "{{citationKey}}" in Zotero 7 is what I've been using, which produces the same effect as Zotfile's "%b" in Zotero 6. The citation keys are generated by Better BibTeX.
  • Anyone have any ideas on this? Really stuck
  • Also, I was under the impression that citation key is a field in Zotero that is usable for file renaming
    As I say, Citation Key is a valid field for two new item types. It's not valid on anything else by default. I don't know if BBT does something to make its citation keys on other item types work for file renaming.

    I'm afraid I can't help on the rest — this appears to all be a plugin-created mess — unless there's some current behavior in Zotero itself (i.e., after restarting in Troubleshooting Mode, which temporarily disables all plugins) that you believe is incorrect. (You shouldn't get the preview shown above — with the duplicated year and title — if the parent item title is set correctly.)

    To be clear, you can manually add a missing extension back to any filename from the right-hand pane after clicking on the attachment. You can then use Rename File from Parent Metadata to rename the file based on the specified format.
  • I know I can manually add the missing extensions, I was looking for a way to avoid having to do that for hundreds of files.

    This was not very helpful, sorry, but I was able to mostly figure this out on my own I believe. For anyone else who runs into something like this, I realize now that the phantom second half of the filenames...was Zotero reproducing what it thought was the file extension. You can see that everything that's sticking follows a period, and so it is keeping everything after that period. That's why I can't get rid of it, because the renaming rules in Zotero 7 don't account for that.

    I was able to mostly fix this by doing some trickery in Zotfile as described in a prior comment. There were some that were still messed up and had these incorrect phantom file extensions, and I went through and manually fixed those. But it wasn't nearly as much work as it would have been.
  • This was not very helpful, sorry
    I mean, as I said, we can't help with convoluted messes created by plugins. I'm not sure why you'd expect that.

    But the renaming behavior when there's no file extension is certainly a bug, so we'll fix that.
  • @GCWealthProject: We've fixed the renaming behavior with no file extension in Zotero 7.0.8. It will also now add a file extension for known file types if an extension is missing.
Sign In or Register to comment.