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?

1 Answer 1


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

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

  • It works. Thanks @Ulrike Fischer! For others: Use "path to the file" rather than ``path to the file''. Nov 27, 2010 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). May 27, 2011 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, 2011 at 20:03
  • Where do the braces around .cpp comes from? Oct 21, 2011 at 7:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .