Formats a path for use in user displays, trim it beautifly.
PrettyPath is useful for trimming down long directory paths or abbreviating them. No attempt is made by PrettyPath to determine the validity of the entered path's syntax or if the path already exists on the server.
The output of PrettyPath is meant for display purposes only. It should not be used programmatically to pass paths to the FileSystemObject for example.
Required. String.
The path to format for display. Can be a virtual, relative or absolute path to a file or folder.
Optional. Integer. Default: 3
Each path element will stop being displayed after this length.
Value can be 0 or greater.
Regardless of the remaining characters in the element, they will be replaced with three dots as placeholders "...".
  if hLen is 2 and the path entered is "c:\winnt\system32" then PrettyPath will format the path as
  If hLen is 0, the path would be "c:\...\..."
Optional. Boolean. Default: False
Show the file name (if path is determined to be a file by prettypath). If set to true, the bExtOnly argument is ignored and the file name in it's entirety (including extension) is shown. Does nothing if the path entered is determined to be a directory path.
Optional. Boolean. Default: True
Show the file extension (if path is determined to be a file by PrettyPath). If True, file extension is shown. If false, extension may be removed depending on the size of hLen.

Private Function PrettyPath(byval sPath, byval hLen, byval bFile, byval bExtOnly)
 Dim elements, i, tmp, bLast, sElm, sDelim, chopsize
 Dim showfullfilename, showfileextension
 chopsize = hLen
 showfullfilename = bFile
 showfileextension = bExtOnly
 if isnull(chopsize) then chopsize = 3
 if isnull(showfullfilename) then showfullfilename = false
 if isnull(showfileextension) then showfileextension = true
 bLast = false
 sDelim = "\"
 if instr(sPath, sDelim) = 0 then sDelim = "/"
 elements = split(sPath, sDelim)
 for i = 0 to ubound(elements)
  sElm = elements(i)
  if len(sElm) > 5 then
   if i = ubound(elements) then
    if showfullfilename then
     tmp = ""
     exit for
    elseif showfileextension then
     tmp = right(sElm, len(sElm) - instrrev(sElm, "."))
     bLast = true
    end if
   end if
   if chopsize > 0 then
    elements(i) = left(sElm, chopsize) & "..."
    elements(i) = "..."
   end if
   if showfileextension and bLast then
    elements(i) = elements(i) & tmp
   end if
  end if
 PrettyPath = Join(elements, sDelim)
End Function

byval sPath, byval hLen, byval bFile, byval bExtOnly

if hLen is 2 and the path entered is &#34;c:\winnt\system32&#34; then PrettyPath will format the path as<br/>&#34;c:\wi...\sy...&#34;;<br/>If hLen is 0, the path would be &#34;c:\...\...&#34;

Views 324 Downloads 92

'FSO', 'PrettyPath', 'beautiful', 'trim', 'abbreviate', 'change', 'convert', 'replace', 'substitute', 'control', 'show', 'fit', 'width', 'NotMyWork'

File System Classic ASP