# Easiest way of having directory tree with hyperref links

I would like to have a dirtree like structure which allows me to have hyperrefs for sections labeled as the file nodes. Something like this:

root
|
|--- dir1
|     |
|     |-- \hyperref[dir1-file1]{''file1''}
|     |-- \hyperref[dir1-file2]{''file2''}
|     |-- \hyperref[dir1-file3]{''file3''}
|--- dir2
|     |
|     |-- \hyperref[dir2-file1]{''file1''}
|--- dir3

\section{dir1/file1}
\label{dir1-file1}
.
.
.


Any idea on how to get this done easily? It's my first crack at putting a document together in LaTex, so the easier the better.

-
What platform are you on? Windows, or Max/Unix? Is the file structure fixed as in the example, or can it grow in depth? Are files only located at that specific depth? –  Peter Grill May 11 '12 at 22:03
Take a look on my answer to “Making TikZ nodes hyperlinkable”: tex.stackexchange.com/a/36185/9237 (where I link to an answer for “Drawing a directory listing a la the tree command in TikZ”). –  Speravir May 11 '12 at 22:33
I'm on OSX. I'm templating the file in JINJA2 and using that to populate the JINJA2 template with syntax highlighted code and dynamically generating the dirtree at the top. With regards to depth, it's arbitrary. –  P. Pietkiewicz May 11 '12 at 23:40

You could use the dirtree package to generate the tree-like directory, and then the \hyperref, \label mechanism from the hyperref to get the hyperlinks: something along these lines:

\documentclass{article}
\usepackage{dirtree}
\usepackage{hyperref}

\begin{document}

\dirtree{%
.1 root.
.2 dir1.
.3 \hyperref[dir1-file1]{''file1''}.
.3 \hyperref[dir1-file2]{''file2''}.
.2 dir2.
.3 \hyperref[dir2-file1]{''file1''}.
.3 \hyperref[dir2-file2]{''file2''}.
.2 dir3.
}

\section{dir1/file1}
\label{dir1-file1}

\section{dir1/file2}
\label{dir1-file2}

\section{dir2/file1}
\label{dir2-file1}

\section{dir2/file2}
\label{dir2-file2}

\end{document}


-