;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfPathCompact (strPath, intWidth, intMode) intLen = StrLen (strPath) If intLen <= intWidth Then Return strPath strDelims = "/\" intDelimLeft = StrScan (strPath, strDelims, 4, @FWDSCAN) intFill = intWidth - intDelimLeft - 3 intDelimRight = intLen intDelimRightLast = intDelimRight intPos = 0 While @TRUE intDelimRight = StrScan (strPath, strDelims, intDelimRight - 1, @BACKSCAN) If (intLen - intDelimRight) >= intFill Then Break intPos = intPos + 1 intDelimRightLast = intDelimRight EndWhile If intPos > 0 strTilde = "" intDelimRight = intDelimRightLast Else strTilde = "~" intDelimLeft = intDelimLeft - 1 - intLen + intDelimRight + intFill - 1 EndIf If intDelimLeft < 3 intDelimLeft = 0 intFill = 3 Else intFill = intWidth - intDelimLeft - intLen + intDelimRight - 1 - StrLen (strTilde) EndIf Switch intMode Case 0 intFill = 3 Break Case 1 Break Case 2 If intFill > 3 intPos = intFill - 3 intFill = 3 While @TRUE intDelimLeft = intDelimLeft + 1 intPos = intPos - 1 If intPos < 1 Then Break intDelimRight = intDelimRight - 1 intPos = intPos - 1 If intPos < 1 Then Break EndWhile EndIf Break EndSwitch strLeft = StrSub (strPath, 1, intDelimLeft) strRight = StrSub (strPath, intDelimRight, -1) Return StrCat (strLeft, strTilde, StrFill (".", intFill), strRight) ;.......................................................................................................................................... ; This UDF "udfPathCompact" removes characters from a given path string ; to make the remaining path string fragment fit into a given width. ; The removed part of the text will be replaced by an ellipsis "..." (here: three point characters) resp. by a series of points. ; ; intMode = 0 ; Returns a shortened pathname inserted with three points (ellipsis) ; Example: ("c:\program files\navigator\programs\bookmark.htm", 45) ==> "c:\program files\...\programs\bookmark.htm" ; ; intMode = 1 ; Returns a shortened pathname inserted with repeated points (no ellipsis) ; Example: ("c:\program files\navigator\programs\bookmark.htm", 45) ==> "c:\program files\......\programs\bookmark.htm" ; ; intMode = 2 ; Returns a shortened pathname inserted with three points (ellipsis) between foldername fragments ; Example: ("c:\program files\navigator\programs\bookmark.htm", 45) ==> "c:\program files\na...r\programs\bookmark.htm" ; ; Detlev Dalitz.20020222.20020524.20020627.20071125.20080404. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. msgtitle = "Demo udfPathCompact (strPath, intWidth, intMode)" :Test1 LongStr = "Z:\Any Folder\Any Folder\Any Folder\Any File.any" intWidth = 36 intMode = 0 ShortStr = udfPathCompact (LongStr, intWidth, intMode) msgtext = StrCat (longstr, @CRLF, ShortStr) Pause (msgtitle, msgtext) :Test2 LongStr = "\\SERVER\SHARE\WINBATCH\2002\FILE.TXT" intWidth = 30 intMode = 0 ShortStr = udfPathCompact (LongStr, intWidth, intMode) msgtext = StrCat (longstr, @CRLF, ShortStr) Pause (msgtitle, msgtext) :Test3 LongStr = "C:\Program Files\Navigator\Programs\Bookmark.htm" iintLen = StrLen (LongStr) For i = iintLen To 1 By -1 intWidth = i ShortStr0 = udfPathCompact (LongStr, intWidth, 0) ShortStr1 = udfPathCompact (LongStr, intWidth, 1) ShortStr2 = udfPathCompact (LongStr, intWidth, 2) ShortLen0 = StrLen (ShortStr0) ShortLen1 = StrLen (ShortStr1) ShortLen2 = StrLen (ShortStr2) msgtext = "" msgtext = StrCat (msgtext, intWidth, @TAB, longstr, @CRLF) msgtext = StrCat (msgtext, ShortLen0, @TAB, ShortStr0, @CRLF) msgtext = StrCat (msgtext, ShortLen1, @TAB, ShortStr1, @CRLF) msgtext = StrCat (msgtext, ShortLen2, @TAB, ShortStr2, @CRLF) Pause (msgtitle, msgtext) Next Exit :Test4 LongStr = "This is a long string to test if it can be shorten." iintLen = StrLen (LongStr) For i = iintLen To 1 By -1 intWidth = i ShortStr0 = udfPathCompact (LongStr, intWidth, 0) ShortStr1 = udfPathCompact (LongStr, intWidth, 1) ShortStr2 = udfPathCompact (LongStr, intWidth, 2) ShortLen0 = StrLen (ShortStr0) ShortLen1 = StrLen (ShortStr1) ShortLen2 = StrLen (ShortStr2) msgtext = "" msgtext = StrCat (msgtext, intWidth, @TAB, longstr, @CRLF) msgtext = StrCat (msgtext, ShortLen0, @TAB, ShortStr0, @CRLF) msgtext = StrCat (msgtext, ShortLen1, @TAB, ShortStr1, @CRLF) msgtext = StrCat (msgtext, ShortLen2, @TAB, ShortStr2, @CRLF) Pause (msgtitle, msgtext) Next :CANCEL Exit