3

Is it possible to have LaTex create folders(directories) in windows I know this is probably impossible , but I've been asked to verify. Pretty sure it's not, that's really not what LaTex is meant for. I've made plenty of research and obtained nothing.

8
  • Why would you need this? Mar 30 '15 at 17:34
  • 2
    Don't know about Windows, but you could on other systems. No idea why you'd want to, but it is possible. (Assuming shell-escape is enabled and allowed to run anything, of course.) This wouldn't really be LaTeX doing it, of course. It would be using whatever is used on the system to create a new directory.
    – cfr
    Mar 30 '15 at 17:38
  • I use LaTex to compile numerous PDFs that are located in different folders. Every now and then I have to make a new compilation of other PDF using the same directory structure. I have been asked if this directory structure can be created using LaTex to avoid having to save a template of it and then copying the directory structure.I know it's weird, but I have to check. Mar 30 '15 at 17:41
  • 1
    A tip for you: tex.stackexchange.com/questions/20444/…
    – Malipivo
    Mar 30 '15 at 17:43
  • 1
    @cfr for windows there is mkdir or md disc:\path for example md C:\dir\pardir\testdir
    – touhami
    Mar 30 '15 at 20:01
5

This may be helpful.

\immediate\write18{md dir}

this create a (dir) directory in the current directory (location of .tex file). I can't do it for absolut path (for example

\immediate\write18{md D:[path]dir}

does not work for me. But we can do it like this

\documentclass{article}

\begin{filecontents*}{mtcd.txt}
@echo off
md D:\pardir\bar
cd D:\pardir\bar
echo hellow world > test.tex
\end{filecontents*}

\begin{document}

\immediate\write18{ren mtcd.txt mtcd.bat}
\immediate\write18{mtcd.bat}
\immediate\write18{del mtcd.bat}

\end{document}

Here we make a .bat file and run it to make our directory after that we delete it.

Edit: Here I complete the example, we can run pdflatex to compile the file created

\documentclass{article}

\begin{filecontents*}{mycmd.txt}
@echo off
set path=D:/mtTex/miktex/bin;%path%
md D:\pardir\bar
cd D:\pardir\bar
(
    echo \documentclass{book}
    echo \usepackage{lipsum}
    echo \begin{document}
    echo test
    echo \lipsum[1-5]
    echo \end{document}
)> test.tex
pdflatex test.tex
\end{filecontents*}

\begin{document}

\immediate\write18{ren mycmd.txt mycmd.bat}
\immediate\write18{mycmd.bat}
\immediate\write18{del mycmd.bat}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.