Avoiding line breaks for file extensions

I have made a system to list a lot of LaTeX files, and I wanted to include the path to all the files, in order to be able to quickly copy-paste it. These paths can get quite long, and fiddling around with some settings gave me the following setup that works well for most paths:

\documentclass{article}
\usepackage{url}

\begin{document}
\begin{sloppypar}
\noindent\path{C:/Folder/Subfolder/Subsubfolder/EvenMoreSubfoldernames/filename.tex}
\end{sloppypar}
\end{document}


This will give nice line breaks for most of my files. In this specific example (and also for some actual files I have), the line breaks only at the file extension, so we would get

C:/Folder/Subfolder/Subsubfolder/EvenMoreSubfoldernames/filename
.tex


as output. Is it possible to avoid line breaks at the file extensions? There should be no dots elsewhere in the path, so avoiding line breaks at dots would also work. I originally used Steven B. Segletes' answer here with \texttt, but this does not combine with the sloppypar environment, and hence usually goes into the margin before breaking.

In summary:

Is it possible to avoid line breaks at the extension of a file path, using \url or \texttt?

• Note that \texttt is just a font command -- your solution wil be independent of this. I think the reason it's used in the linked answer is just to match the style of the \url macro. – Chris H Aug 12 '15 at 10:42
• This answer may point you to the right direction in the docs for url, as it discusses the definition of which characters can allow breaking -- though I don't see . in the list. – Chris H Aug 12 '15 at 10:47

Just suppress in the textttt answer the possibility to have linebreak on ..

\documentclass[a4paper]{article}
\renewcommand{\texttt}[1]{%
\begingroup
\ttfamily
\begingroup\lccode~=/\lowercase{\endgroup\def~}{/\discretionary{}{}{}}%
\begingroup\lccode~=[\lowercase{\endgroup\def~}{[\discretionary{}{}{}}%
%\begingroup\lccode~=.\lowercase{\endgroup\def~}{.\discretionary{}{}{}}%
%  \catcode/=\active\catcode[=\active\catcode.=\active
\catcode/=\active\catcode[=\active
\scantokens{#1\noexpand}%
\endgroup
}

\begin{document}
\begin{sloppypar}
\noindent\texttt{C:/Folder/Subfolder/Subsubfolder/EvenMoreSubfoldernames/filename.tex}
\end{sloppypar}
\end{document}


Here's an alternative approach, tweaking the behaviour of \url:

\documentclass{article}
\usepackage{url}
\def\UrlBreaks{\do\@\do\\\do\/\do\!\do\_\do\|\do\;\do\>\do\]%
\do\)\do\,\do\?\do\&\do\'\do+\do\=\do\#}%
\begin{document}
\begin{sloppypar}
\noindent\path{C:/Folder/Subfolder/Subsubfolder/EvenMoreSubfoldernames/filename.tex}
\end{sloppypar}
\end{document}


The line starting \def\UrlBreaks (in fact split over 2 lines) is lifted from url.sty, with \do\.` removed. What it does here is redefine the list of characters at which urls can be broken to exclude full stops.