hyperref: How to open a directory view with href{...}?
The root of the problem is that hyperref tries to be smart. If no file extension is found, hyperref adds .pdf
, so the link becomes either abc.pdf
or abc/.pdf
depending on whether there is trailing /
in the call.
You can define your own command, say, \HREF
, which simply constructs the link and does not do anything else.
This works for me:
\documentclass{article}
\usepackage{hyperref}
\makeatletter
\newcommand\HREF[2]{\hyper@linkurl{#2}{#1}}
\makeatother
\begin{document}
\HREF{tmp}{open directory \texttt{tmp}}
\end{document}
Note that this works in xpdf
. Acrobat disables such links by security reasons. evince
works with absolute paths (file:///home/boris/scratch
) but balks at relative ones: somehow ../tmp/
works, but ./tmp
does not. I guess this is some bug in evince
.
As Boris said in his answer, .pdf
is appended if no extension is found.
To avoid this, use \href{abc/.}{Open directory}
. The .
(current directory) looks like a file extension.