How to get shortened path from file

I’d like to use helptags to show the path to a previously opened file.

Some of the full paths are quite long. Messy

Ive seen representations of long strings where you get the start, some dots, and the end

eg

users/somebody/sa…./fiename.txt

Is there a function or plugin that would give that kind of formatting?

Here’s one I use:


Public Function ShortenString(s as string, maxLength as integer = 80) As String
  // if short enough, just return the source String
  if s.length <= maxLength then
    return s
  end if
  
  // Otherwise, create a string from the left and right ends,
  // and removing extra characters to make room for the ellipsis in the middle
  // note: this probably requires ellipsis to have even length
  var ellipsis as String = "...."
 
  s = s.left(maxLength/2 - ellipsis.length/2 ) + "...." + s.right(maxLength/2 - ellipsis.length/2)
  
  return s
  
End Function
1 Like

Just mentioning Apple HIG, which refers to the preferred ellipsis character being the single character “…”. For what it’s worth.

3 Likes