# How can I create a subfolder with filecontents?

As shown in this MWE

\RequirePackage{snapshot}
\documentclass{scrbook}
\usepackage{filecontents,biblatex}
\begin{filecontents}{bib/\jobname.bib}
@misc{anything,
author={A. Anyone}}
\end{filecontents}

\begin{document}
\chapter{My document}
This is my text
\end{document}


I like to have the bibliography in the subfolder bib. But filecontents cannot create the folder however I have --shell-escape enabled:

! I can't write on file bib/bundledocbib.bib'.
\relax
l.4 \begin{filecontents}{bib/\jobname.bib}

• filecontents suppose to make the content of a file available to your code as there was a file there (that is not true). I don't see a reason to make "iconic folders" because folders is out of scope for combination of filecontents with tex (that just need a way to read the contents of every file and doesn't care for it's location anymore). – koleygr Feb 24 '18 at 22:56

If you really have -shell-escape enabled you can create the folder before the first use (here with windows commands):

\documentclass{scrbook}
\usepackage{filecontents,biblatex}
\usepackage{shellesc}
\ShellEscape{mkdir bib}
\begin{filecontents}{bib/\jobname.bib}
@misc{anything,
author={A. Anyone}}
\end{filecontents}

• I agree, wouldnt build bigger tex-projects with filecontents either, but needed it for demonstration purpose with bundledoc`. – LukasCB Feb 24 '18 at 23:32