Move folder with PDFs and have JabRef reconnect links to them automatically

Hi there,

As is written in the subject, is there a possibility to move a folder (while keeping its structure intact and/or different) with my PDFs and have JabRef reconnect links to them automatically after the fact?

For example, move

\level 1\level 2\PDFs\
to
\level1\PDFs\
or to
\newfolder\newsubfolder\PDFs\

and suffer no consequences?

I would’ve tried on my own, but I’m afraid to mess up with the database and then not being able to go back. Yes, I know I can create a copy of it, but still it’s better to ask.

HI,

welcome to the wonderful magic fature of JabRef, renaming and moving files :wink:
It’s definitely advisable to create a copy of your bib file.

JabRef can rename files, create directories and move files to those directories, it’s very flexible, but depends on how you organize your files.

  1. Do you have a sinlge folder where you put alll your pdf?
    Then it’s probaly simple. Just change the main file directory in the preferences to the new one and to a Cleanup -> move files to folder. Then JabRef should move the files to the folder.

Before you do this for all files using the Cleanup operation it’s advisable to test it with a single entry first.
Right click the file in the gernal tab -> Move

Hi Cristoph and thanks for your reply.

My organization is like this: I have a main folder which doesn’t contain any PDFs, but only the folder structure (organized thematically). The PDFs are located down in the subfolders, at multiple levels.

Finally, all PDFs are named according to my own naming scheme (i.e. Author - Title . Subtitle [year].pdf) that I’d like to keep.

Is there a possibility I move somewhere else the whole main folder with the structure and naming as they are now, and then just make JabRef relink them as they were?

I guess the alternative would be to replace the path string inside the .bib file for each entry, which I would avoid doing unless absolutely necessary.

Each users organizes the files slightly different. If you have the file paths stored relatively in the .bib file, this is no issue. If not, you can use the cleanup action to convert the paths to relative ones (see https://docs.jabref.org/finding-sorting-and-cleaning-entries/cleanupentries).

Then you can use the preferences of the current library to change the starting search path: https://docs.jabref.org/faqgeneral#q-how-do-i-link-external-files-with-paths-relative-to-my-bib-file-so-i-can-move-my-library-along-with-its-files-to-another-directory

Then, it should be no issue to move around the diretory.

Hi there,

I am resurrecting this (kinda) old thread.

I recently did a reorganisation of my PDF files and folder structure. What this means is that I moved them to other places, did some reshuffling, etc. but all PDF filenames remained the same.

I also tried to clean up the database (as suggested above by @koppor) and to make PDF paths relative. Unfortunately, this did not make PDF paths relative as I can see that they are still fixed as they were.

EDIT: I also just discovered and tried the Automatically set file links option in the Quality menu, to no avail. Mind that in Library → Library properties the General file directory is set to “.” i.e. the directory where the .bib file is located. But JabRef still cannot find the files anyway. It just searches for the files and then says: Finished automatically setting file links. No files found.

What I need to do, actually, is to reconnect all the entries in my .bib database to the original PDF files that were shuffled around. Is this possible at all? Can JabRef rediscover them automatically by filename i.e. author - title [year].pdf?

Hi,

Have you unchecked the option “Search and store files relative to library locaiton”?
This takes precedence over all other options.
And you also need to set the filename format pattern in the preferences under LInked files then to [author] - [title] - [year]

Thanks, I’ll try it and let you know how it went.

BTW why does this have to be so complex and fiddly? All entries already have the filename in them. JabRef can simply search for that filename within a folder structure and discover all files. If there are conflicts, it can simply show a window picker so that the user can resolve them manually (just like with fetching data).

Hi,

sorry for the confusion, I mixed the dialogs up.

JabRef does exactly that, it looks for the files in the folders, that is exactly what the Automatically set linked files does. It’s controlled by these options:

This prevents it from taking up any other unwanted files.

Hi Christoph,

Thanks for attempting to help me. Unfortunately, what you suggested doesn’t work i.e. JabRef finds no files. :frowning_face:

It seems that I’ll have to do this with another, external script or software of a sort. One that would search for strings in the .bib database ending in .pdf, then find the location of the matching filename, and then replacing the path in the .bib database.

Do you have any idea what software can I try for this purpose?

Oh no. We can get this working together!
First of all, try the latest development version of JabRef. index - powered by h5ai v0.29.0 (https://larsjung.de/h5ai/)

Then I need the path info about the location of the pdf and second the path of the bib file. Then I can tell you more

I’m having a very similar problem. I just set up Jabref a few days ago, and linked a bunch of papers that I have in a folder on my Desktop. Then I downloaded a bunch of files from online, which Jabref automatically put in its own folder. Wanting to store all the files in the same folder, I moved everything to a third folder, not realizing it would break all my links within Jabref. I wish I’d seen this thread before I started!

I have done the following:

  • set the main file directory to the new directory
  • unchecked “Search and store files relative to library locaiton”
  • changed the “linked files” > “Autolink files” preference to “Use regular expression search”, per @Christoph’s screenshot
  • ran “Automatically set file links” in the Quality menu

Like “And” above, I get “Finished automatically setting file links. No files found.”

The files are now located in “/home/shauna/Desktop/misc/readings”. The bib file is in “/home/shauna/snap/jabref/1631” which appears to have been created on installation/first run. The bib file upon inspection is using full paths refering to the old folder structure.

Jabref version: JabRef 5.6–2022-04-25–5c9d898
Linux 5.13.0-51-generic amd64
Java 17.0.2
JavaFX 18+12

Reading your comment, @Shauna_GM , I think what you did looks already pretty good. I am not sure why it does not work. I think it should.

I have a suspicion, though:

Keep in mind, regular expression search (RegEx search) depends on the filenames of your PDFs. If the filename does not match your RegEx, nothing will be found.

You can create very complicated RegEx patterns to detect very complicated filenames. The Syntax JabRef uses mainly follows citationkey patterns as described here: Customize the citation key generator - JabRef
See also Searching within the library - JabRef

If my suspicion is right and the RegEx does not detect your file-names, I would suggest to adapt your RegEx to fit your current file-names or alternatively to rename your PDF files to fit your current regex.

Alternatively, you can use the Edit > Find and replace (CTRL + R) tool to replace your old folder structure in the file field with your new folder structure.

Example:

The find and replace ended up being the simplest solution. (I did try fiddling with the regex, but doing so caused “Automatically set file links” option to become greyed out/inaccessible. Maybe my fiddling led to invalid regexes? It looked right but regexes are capricious beasts.) Anyway, thank you so much for the help!

2 Likes