wshanks / Zutilo

Zotero plugin providing some additional editing features
Other
1.51k stars 72 forks source link

Modify attachment path by appending to the start (not replacing anything) #212

Closed evodevosys closed 2 years ago

evodevosys commented 2 years ago

I use zotero with attachments stored in a dropbox folder and linked into zotero records using zotfile. I have the zotero library (minus attachments) synced on zotero cloud.

I had to migrate to a new computer and when I repopulated my library and then redownloaded the attachments and pointed to them using zotfile, it seems to have lost the path. When I use Zutilo to show the path to attachments for attachments I made before the migration, it just shows the file name. When I try to open these in zotero it can't find them. Attachments I made after the migration work fine and show the full path name when I use zutilo to look.

I was going to use zutilo to batch add the folder path to the linked attachments for all files before the migration, but Zutilo's "Modify attachment paths" looks like it is a string replacement function, and I need to prepend a folder path to the start.

e.g. I want the path to look like:

attachment: C:\Users\g\Dropbox\ZoteroAttachments\File1.pdf but currently it looks like attachment: File1.pdf

where C:\Users\g\Dropbox\ZoteroAttachments is the custom location of file I have set in my ZotFile preferences.

Thanks for any help

Zotero 5.0.96.3 Zutilo: 3.10.0 Zotfile: 5.0.16

evodevosys commented 2 years ago

Solved it - I see that the "attachments:" isn't there on the ones where it is linked properly, so I replaced "attachments:" in the path name with "C:\Users\g\Dropbox\ZoteroAttachments\" and the files are now relinked.

qqobb commented 2 years ago

I see that the "attachments:" isn't there on the ones where it is linked properly

Zutilo's "Show attachment paths" function shows "attachments:" for linked files with a relative path in the Linked Attachment Base Directory. You'd only have to update the base directory setting next time the base directory changes. See also here.

evodevosys commented 2 years ago

@qqobb - thanks for your comment. I'm not sure I quite understand, though, and perhaps I am missing something in my zotero configuration. My Linked Attachment Base Directory in Zotero itself is blank. I have my attachments directory set in the ZotFile preferences. My thinking was that I wanted Zotfile to be managing the attachments, not Zotero itself. Is this incorrect? Do I also need to set the linked attachment base directory in zotero as well?

If I use zutilo to look at the attachment paths for articles I've recently imported, it shows the full path (no "attachments:"). And since I did the replace using zutilo's modify attachment paths this is true for most of the articles in my library. What's odd is that I keep coming across articles in my library where the modification didn't work for some reason - the attachments aren't linked and show attachment paths shows "attachments:" I systematically went through, sorted my library by year added, and modified the paths in chunks by year. It's not like a whole year still lists "attachments:" It's some articles here or there that aren't even at the beginning or end of the year.

wshanks commented 2 years ago

@evodevosys for the set up you have described (storing all your attachments below a single parent directory), you would benefit from setting the Linked Attachment Base Directory, though you don't have to use it. Doing this will drop that initial path from any linked attachment that starts with that path when storing the path in Zotero's internal database. Then whenever the attachment path is needed later, it will be prepended. If you change computers again or migrate away from Dropbox or something like that, you just need to update this Zotero setting for the new parent location of your attachments and do not need to use Zutilo's modify attachments function to change the initial path.

I am not sure what could lead to you seeing attachments: prepend your paths if you have not used the Linked Attachment Base Directory previously (having that preference set is the only way I know to get attachments: at the beginning of an attachment path). If the path after attachments: matches what you want, perhaps setting the Linked Attachment Base Directory will take care of getting the path right for those remaining attachments you are finding that did not get set to absolute paths as well.

Wow, it's been 10 years since I helped get the Linked Attachment Base Directory feature added to Zotero (https://github.com/zotero/zotero/pull/51).

evodevosys commented 2 years ago

@wshanks Thanks for your reply. I wonder whether I had that Linked Attachments Base Directory set on my old computer and then neglected to set it when I migrated computers. Perhaps that would explain why I saw "attachments:" when I switched and the more efficient solution was just to set it like you say rather than going this whole Zutilo modifying directories route. I'll try it and see.