# Defining a case dependent default path

I am using latex together with the cloud service Nextcloud. As a result, I compile the same .tex file from different machines, such that all my figures have different global file paths.

To solve this problem, I want to define a default path command \defpath{file} that automatically identifies the correct global path based on where my library file is located (I have a fixed path for that which I don't touch).

I tried to use the following:

\IfFileExists{
/path/to/source1/libdirectory/library.bib
}
{
\newcommand{\defpath}[1]{{"/path/to/source1/#1"}}
}{
\newcommand{\defpath}[1]{{"/path/to/source2/#1"}}
}

But this gives the error message

Illegal parameter number in definition of \reserved@a. ...ath}[1]{{"/path/to/source1/#1"}}}

It tried to create a minimal working example, but the problem seems to be sensitive to my folder structure which is not reproducible for readers of this. I am also rather confused because a similar if-clause for my library

\IfFileExists{
/path/to/source1/library.bib
}{
\bibliography{path/to/source1/library}}
{
\IfFileExists{
/path/to/source2/library.bib
}{
\bibliography{/path/to/source2/library}
}{
\bibliography{library}
}
}

works just fine. Also if I leave out the if-clause and define the default command by hand

\newcommand{\defpath}[1]{{"/path/to/source1/#1"}}

it also works. So it is somehow the interaction between the two that causes the error.

Any clues to where this strange behavior might come from would be appreciated. Also alternative best practices to define a default path would potentially be useful.