title: How to truncate a string (containg a path) without touching the filename?
body: <p><strong>How to truncate a string (containing a path) without touching the filename (keep the last folder, the filename and the drive letter)?</strong></p>
  
  <p>Hi,
  I'm looking for a way to truncate a path to fit a specified width.</p>
  
  <p>I already search on SO and I found this:
  <a href="https://stackoverflow.com/questions/282758/truncate-a-string-nicely-to-fit-within-a-given-pixel-width">Truncate a string nicely to fit within a given pixel width</a></p>
  
  <p>But it's adding ... at the end of the string. I would like to have a similar function but it need to keep the begining and the ending..</p>
  
  <p><strong>For exemple, I have this path (string):</strong></p>
  
  <pre><code>H:\Informatique\Personnalisation\Icones\__\Crystal GT PNG Pack\Applications\licq.png
  </code></pre>
  
  <p>And it need to fit the div's width like this:</p>
  
  <pre><code>H:\Informatique\...PNG Pack\Applications\licq.png
  </code></pre>
  
  <p><strong>Another exemple:</strong></p>
  
  <pre><code>D:\A___VERY___________LONG________PATH____________\myfile.png
  </code></pre>
  
  <p>Will be shorten to:</p>
  
  <pre><code>D:\A___VERY___________LONG________PA...\myfile.png
  </code></pre>
  
  <p><strong>Last exemple:</strong></p>
  
  <pre><code>D:\A___VERY___________LONG________PATH____________\and-a-sub-solder\myfile.png
  </code></pre>
  
  <p>Will be shorten to:</p>
  
  <pre><code>D:\A___VERY________...\and-a-sub-solder\myfile.png
  </code></pre>
  
  <p>Restriction:</p>
  
  <ul>
  <li>The drive part is required (H:)</li>
  <li>The filename and the extension is required (licq.png)</li>
  <li>If there's multiple folders, the last folder must not be truncate, exept if everything is already truncated and it is the only way to
  make the string shorter.</li>
  <li>If the filename is too long, truncate it in the middle.</li>
  </ul>
  
  <p><strong>Long filename exemple:</strong></p>
  
  <pre><code>D:\my____file___________________________name____is___too____________long.png
  </code></pre>
  
  <p>Will be shorten to:</p>
  
  <pre><code>D:\my____file_________..._is___too____________long.png
  </code></pre>
  
  <p>I see windows and apple doing it the nice way... but I can't find any script that is near that.</p>
  
  <p>Any link with similar script so I can try adjust it?
  Or anybody who wants to help me with that? :)</p>
  
  <p>Thank you very much</p>