# how do I use the \input command on windows, combined with \IfFileExists?

I'm trying to use a command in my LaTeX file that inputs a file if it exists, and if it doesn't exit, inputs another one. This is the command:

\IfFileExists{/media/kingstonGB/LaTeX/preamble}{\input{/media/kingstonGB/LaTeX/preamble}}{\input{E:\\LaTeX\\preamble}}


In short, the command searches for the file in /media/kinstgonGB (which should succeed on my unix systems, and if it finds it, inputs it. Otherwise, if that file is not found, it means the LaTeX is being compiled on a Windows system, so it should look for files in E:\. However, I get this error message:

! LaTeX Error: Missing \begin{document}.


I've also tried wrapping E:\LaTeX\preamble in quotes, or escaping it (as done here), or both, and the error is the same.

-
–  Leo Liu Nov 29 '11 at 13:45
I think you may be abusing the \IfFileExists command: What you're looking for should be a file, but the command's first argument looks like a path to a file, not a file itself. Or is there maybe a file named preamble.tex? If so, it might be a good idea to add the .tex extension explicitly and try recompiling. Separately, you may want to add a second \IfFileExists instruction, in the second argument of the first such command, to check explicitly for the existence of the file e:\\LaTeX\\preamble.tex -- unless you're always good and never forget to insert the USB key. :-) –  Mico Nov 29 '11 at 13:52
There is a file named preamble.tex. I use a standard preamble for all of my LaTeX documents, so I normally input it in the header. I don't need to specify the .tex extension with the \input command, though, right? –  Ricardo Altamirano Nov 29 '11 at 13:54
No, it's not necessary to add the extension .tex, but doing so wouldn't hurt the code's legibility either. :-) Re-check the error message you're getting: is it being generated by the \IfFileExists command, or is it maybe being generated by some instruction contained in preamble.tex? For instance, do you get the same error message if the file preamble.tex is in your current working directory and you load it from the main driver file with the command \input preamble? –  Mico Nov 29 '11 at 13:56
There is also the macro \InputIfFileExists –  Alain Matthes Nov 29 '11 at 14:05

Note, that there is also a \InputIfFileExists:

\InputIfFileExists{/media/kingstonGB/LaTeX/preamble}{}{
\input{E:/LaTeX/preamble}%
}

-
Excellent! That makes the code much more readable as well. –  Ricardo Altamirano Nov 30 '11 at 14:34

/ works for both *nix and Windows.

\input{E:/LaTeX/preamble}

-
Working perfectly, and thank you for the link in your comment as well. It's a great resource. –  Ricardo Altamirano Nov 29 '11 at 13:51