# \graphicspath : Images with duplicate filenames, different folder locations [2017.07]

This is a continued thought from here.

If I have a figure folder hierarchy such as:

./Figures/Apple/a.pdf
./Figures/Apple/b.pdf
./Figures/Apple/c.pdf

./Figures/Banana/a.pdf
./Figures/Banana/b.pdf
./Figures/Banana/c.pdf

Is there any method to string search all paths,
such that in scenarios in which:

``````\includegraphics{a.pdf}
``````

has duplicates, the user could use a partial path string
to still get the image, such as:

``````\includegraphics{Figures/Banana/a.pdf}
\includegraphics{/Banana/a.pdf}
\includegraphics{Banana/a.pdf}
\includegraphics{ana/a.pdf}
\includegraphics{a/a.pdf}
``````

All of these should find a unique answer in the search path.

I understand that the full path could get me there,
but in cases where that path is long and could easily change,
it would be nice to only need to extend the string
until it becomes unique.

• @DavidCarlisle : Even when not writing the whole word, like with `ana` and `a`? I just assumed it wouldn't work without some additional tool.. Jul 6 '17 at 20:46
• oh sorry I misread no you need the directory name, I'll delete first comment. Jul 6 '17 at 21:00
• `Figures/Banana/a.pdf` `Banana/a.pdf` and `a.pdf` should all work if TEXINPUTS includes `.//` or `./Figures//` Jul 6 '17 at 21:02
• My first idea would be to use `\graphicspath`. If that is too repetitive, e.g. because you have too many documents, I would suggest to create shortcuts in the form of symlinks; you can then update in one place only in case your folder locations to actually change. Jul 6 '17 at 21:25

You could indeed use a very large `\graphicspath` like:
``````\graphicspath{%
With this `a` will be found as `Figures/Banana/a.pdf` very soon, but `/Apples/b.pdf` will try `Figures/Banana//Apples/b.pdf`, `Figures/Banana/Apples/b.pdf`, `Figures/Banana/Apples/b.pdf`, `Figures/Banan/Apples/b.pdf`, `Figures/Bana/Apples/b.pdf`, `Figures/Ban/Apples/b.pdf`, `Figures/Ba/Apples/b.pdf`, `Figures/B/Apples/b.pdf`, `Figures/Apples//Apples/b.pdf`, `Figures/Apples//Apples/b.pdf`, `Figures/Apples/Apples/b.pdf`, `Figures/Apple/Apples/b.pdf`, `Figures/Appl/Apples/b.pdf`, `Figures/App/Apples/b.pdf`, `Figures/Ap/Apples/b.pdf`, `Figures/A/Apples/b.pdf` before it will find `Figures//Apples/b.pdf` or `Figures/Apples/b.pdf`.
And if there would be additional sub-folders like `Figures/RedApples` it could be hard for the user to always have the correct `a.pdf`. So at the end the suggestion could result in more mess than comfort. I would not do it. Instead I would only use `\graphicspath{{Figures/}}` and always use `\includegraphics{Bananas/a}` to have the banana picture and `\includegraphics{Apples/a}` to get the apple picture.