Moving the linked files folders to a different drive

Hi, I use Zotfile. I moved the folder where I have my PDFs (it is called "Zotfile"), which are only linked in Juris-M (a Zotero fork), from D:/ to C:/.

I changed the linked attachment base directory in the preferences.

I also changed the Zotfile directory in the Zotfile preferences.

I suspect that maybe my Juris-M didn't treat the directory as a relative path, but as an absolute path.

Yet, Juris-M can't find the linked PDFs when I double-click them.

It would take a long time to manually localize every linked PDF in Juris-M.

Any ideas how I can redirect the links? Should I use system links in Windows? BTW, as of now I don't have a fixed drive that I assign to D:/ all the time.
  • This certainly should have worked using the base directory, but since it didn't, you can batch-move links using the Zutilo add-on:
  • Thanks!

    I replaced the links using Zutilo.

    I replaced "D:\username\Dokumente\ZotFile" with "C:\Users\username\Documents\ZotFile".

    Strangely, the link targets now usually lack the first letter of the filename. I don't know if this was the case already before executing the Zutilo action.


    The Juris-M item is titled: 2012 - »There is no rule of law in China – not yet« – 4th.pdf

    The link target in Juris-M is named: 012 - »There is no rule of law in China – not yet« – 4th.pdf

    The real file in the Zotfile folder is titled: 2012 - »There is no rule of law in China – not yet« – 4th.pdf
  • > Strangely, the link targets now usually lack the first letter of the filename.

    Does someone have an idea what I could do?
  • I'd guess that it's something to do with the backslash and how Zutilo handles that (or doesn't handle that, particularly if it wasn't developed on Windows). A backslash is an escape character in JavaScript, but only Windows uses backslashes in paths.

    Unless that data — meaning the first letter — exists somewhere, there wouldn't be any sort of automated way of recovering those beyond relinking the attachments from the file-not-found dialog.
  • Thanks for your answer. It's a pity… I will do it through said dialog.

    I want to tell every other user to whom this happens: Consider DocFetcher as an alternative tool for indexing and searching.
  • @moebio: I couldn't reproduce your error with the missing first character. Were you working with files in the Linked Attachment Base Directory? Do you remember your old and new partial paths?

    It might be possible to grab the first characters or the full filenames from your attachment titles. Then it could be possible to adapt Zutilo's code (here) and use it with Zotero's JavaScript API, but this could be quite involved.

    There could be an easy partial solution for filenames that are starting with a year. You could, e.g., modify the partial paths from "C:\test1\0" to "C:\test1\20".

    There is also this add-on that might help with removing broken attachments:

    I'll provide some general advice on the Zutilo function below.
  • Zutilo's "Modify attachment paths" function is very flexible, so it should be used carefully. Before using this function, remember to back up your Zotero data. Here, your main concern should be the zotero.sqlite database file. (Zotero also keeps automatic backups of recent versions the zotero.sqlite database that might help in some cases.) Note that this Zutilo function is not touching paths on your filesystem. It's only changing the pointers to linked files within Zotero's database.

    Normally, you wouldn't need to use Zutilo's "Modify attachment paths" function. Working with Zotero's Linked Attachment Base Directory setting should generally be your preferred option.

    If you decide to use Zutilo's "Modify attachment paths" function:

    1. Test the function on a small number of attachments first. In case you experience a problem, this allows you to manually correct the paths. If everything works as intended, you can modify all linked files.

    2. Zutilo's "Modify attachment paths" function should always be used in combination with its "Show attachment paths" function. It will replace one character sequence in the output of the "Show attachment paths" function with another character sequence. By default, it will only replace the beginning of attachment paths. If you click the "replace all instances" check box, it can also replace something in the middle of the paths, e.g., replacing \ with /.

    3. Zutilo's "Show attachment paths" function shows you a relative path of a linked file in the Linked Attachment Base Directory as "attachments:references/coolPaper.pdf". For a linked file that is not stored with a relative path, Zutilo shows its absolute path, e.g., "C:\userData\references\coolPaper.pdf". A file in Zotero's storage is shown as "storage:coolPaper.pdf". Zutilo won't touch stored files.
  • Here are some tests on Windows for using the "Modify attachment paths" function on linked files stored with absolute paths. You can see that you can mess up your paths. But it's working as expected, given the flexibility of the tool.

    modify partial paths:
    old C:\test1\
    new C:\test2\
    filename change:
    old C:\test1\123.pdf
    new C:\test2\123.pdf

    modify partial paths:
    old C:\test1
    new C:\test2
    filename change:
    old C:\test1\123.pdf
    new C:\test2\123.pdf

    modify partial paths:
    old C:\test1\
    new C:\test2
    filename change:
    old C:\test1\123.pdf
    new C:\test2123.pdf

    modify partial paths:
    old C:\test1
    new C:\test2\
    filename change:
    old C:\test1\123.pdf
    new C:\test2\\123.pdf
  • edited August 28, 2020
    There's an earlier discussion about the same issue. I'm wondering whether the use of the substr function could be problematic (here) in combination with backslashes, but I'm not sure.

    @moebio: Could you provide as much information as possible about how this happened? If there is an issue with the Zutilo code, this might help finding it. Did it happen on a Windows-only setup?
  • Sorry, I tried to describe what I did in as much detail as possible in the entry post. I made the post not immediately after making the changes, but some hours or days later. I hope that I can answer with more information if specific questions come up.

    About the setup, yes, I have been using Windows only.
  • Here are some more specific questions.

    Information on the issue:

    1. Can you provide the Juris-M and Zutilo versions that you were using?

    2. Do you remember whether you clicked the "replace all instances" check box?

    3. You wrote that the links "usually lack the first letter". Does this mean that not all attachments were affected in the same way? If some attachments were fine, could this be related to a difference in the first character of the filename?

    4. Are all your linked files saved to Zotfile's "Custom Location" without subfolders? (Did you leave "Use subfolder defined by" unchecked?)

    5. It would be great if you could try to reproduce the issue on a test item. First, create a new linked attachment. Select this attachment and use Zutilo's "Show attachment paths" and "Modify attachment paths" functions to set the path to the original path of an attachment that ended up with a missing character. If this works, see if you can reproduce the issue.

    Fixing your problem:

    6. Did you check whether you have a backup as described above?

    7. If you haven't fixed your paths yet, I could try to write a script that uses the attachment titles for fixing the filenames.
Sign In or Register to comment.