In a recent project, I wanted to create a diagram of a repository for the appendix of a paper, including comments to highlight key files and explain how the folders were organised. I found this answer on Stack Exchange by user Gonzalo Medina, which I tweaked to produce the diagram below.

An annotated directory structure.
An annotated directory structure.

The code is below:

% Adapted from


\newcommand{\size}[2]{ {\fontsize{#1}{0}\selectfont#2}}
\newcommand{\comment}[0]{\color{blue} \rm}

  \node[inner sep=0pt, minimum size=#1](-foldericon){};
  \node[folder style, inner sep=0pt, minimum width=0.3*#1, minimum height=0.6*#1, above right, xshift=0.05*#1] at (-foldericon.west){};
  \node[folder style, inner sep=0pt, minimum size=#1] at ({};}
  folder style/.style={draw=foldercolor!80!black,top color=foldercolor!40,bottom color=foldercolor}

\forestset{is file/.style={edge path'/.expanded={
    ([xshift=\forestregister{folder indent}]!u.parent anchor) |- (.child anchor)},
    inner sep=1pt},
  this folder size/.style={edge path'/.expanded={
    ([xshift=\forestregister{folder indent}]!u.parent anchor) |- (.child anchor) pic[solid]{folder=#1}}, inner xsep=0.6*#1},
  folder tree indent/.style={before computing xy={l=#1}},
  folder icons/.style={folder, this folder size=#1, folder tree indent=3*#1},
  folder icons/.default={12pt},


  for tree={font=\ttfamily, grow'=0, folder indent=.9em, folder icons}
          [experts\_extant.csv {\comment (which species are common and extant according to experts)}, is file]
          [merged.csv {\comment (the plants database merged from different herbaria and museums)}, is file]
          [first\_last\_detns\_final.csv {\comment (input to SEUX model)}, is file]
      [undetected\_extinctions {\comment (shared SEUX model functions)}