TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the listings package and the path to the source code contains some spaces. For example, the path can be /some dir/sub dir/file 1.txt and
\lstinputlisting{/some dir/sub dir/file 1.txt} does not work.

Is there a way to fix this problem?

share|improve this question
up vote 11 down vote accepted

In windows/miktex it works if you quote the name:

\lstinputlisting{"some dir/sub dir/file 1.txt"}

share|improve this answer
It works. Thanks @Ulrike Fischer! For others: Use "path to the file" rather than ``path to the file''. – xport Nov 27 '10 at 14:20
+1 Works also for me with TeXLive 2011 under Linux. My first attempt to use an extra set of braces doesn't work (Error: Too many }'s). – Martin Scharrer May 27 '11 at 11:53
As a note this does not appear to work on TeXLive2011/Win7 ! Package Listings Error: File `''C:/Users/MyName/Documents/Uni/Principles of Programming/cs2303/Assigments/Assigment 3/atom/atom(.cpp'')' not found. – Canageek Oct 20 '11 at 20:03
Where do the braces around .cpp comes from? – Ulrike Fischer Oct 21 '11 at 7:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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