Menu

#1 Truncate (smartly) file names in lists

open
nobody
5
2005-12-06
2005-12-06
No

Unusually long file names will severely upset the file
list UI. They will be shown in full, thus making their
column too wide. My suggestion is to truncate file
names in the list and other width-sensitive,
not-easily-wrapping places. I also suggest that the
function be "smart" in the following sense (default
behavior in OS X Finder):

Filename: This is a very long filename1.jpg

Should truncate to: This is...filename1.jpg

The process would go something like this:

Explode string into words. If there is only one word
and it is longer than MAX_LEN, truncate to MAX_LEN and
add ellipsis and extension. (e.g.
"Supercalafrag...jpg"). If there is more than one word,
take the length of the last word and if it is <
MAX_LEN, append it to MAX_LEN - strlen(last word), e.g.
"This is a... filename.jpg".

In short, attempt to display as many words as possible,
truncating and adding the ellipse before the last word.
The purpose in this (rather than "This is a very
long...jpg") is to distinguish prefixed or
incrementally numbered file names (e.g. "School
portrait 120.jpg", "Yosemite - summer - pool.jpg")

Discussion

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.