All pastes #277248 Raw Edit

macgeek

public text v1 · immutable
·published 2006-12-13 01:10 UTC
rendered paste body
Function GenerateDirectoryListing(pF As FolderItem, pResource As String) As String
  ' for the sake of a realistic example,
  ' say that pF.ShellPath = "/home/ben/test-folder"
  ' and pResource = "/test-folder"
  dim f as FolderItem
  dim html,names(),s as string
  dim i,max,sizes() as integer
  f=pF
  if f.Directory then
    html="<html>"+EndOfLine
    html=html+"<head>"+EndOfLine
    html=html+"<title>Listing of "+pResource+"</title>"+EndOfLine
    html=html+"</head>"+EndOfLine
    html=html+"<body>"+EndOfLine
    html=html+"<h1>Listing for "+pResource+"</h1>"+EndOfLine
    html=html+"<pre>"+EndOfLine
    for i=1 to f.Count
      names.Append f.item(i).Name
      if f.item(i).Directory then
        sizes.Append -1
      else
        sizes.Append f.item(i).Length
      end
    next
    max=30
    html=html+"Name"+RightBufferSpace("Name",max)+"Size<hr />"
    html=html+"<a href=""../"">Parent Directory</a>"+RightBufferSpace("Parent Directory",max)+"--"+EndOfLine
    if UBound(names)>-1 then
      for i=0 to UBound(names)
        s=names(i)
        if len(s)>max then
          s=left(s,max-3)+"..."
        end
        if rightb(pResource,1)="/" then
          html=html+"<a href="""+pResource+names(i)+""">"+s+"</a>"+RightBufferSpace(s,max)
        else
          html=html+"<a href="""+pResource+"/"+names(i)+""">"+s+"</a>"+RightBufferSpace(s,max) 
        end
        if sizes(i)=-1 then
          html=html+"--"+EndOfLine
        else
          html=html+FormatSize(sizes(i))+EndOfLine
        end
      next
    end
    html=html+"<hr /></pre>"+EndOfLine
    html=html+"<h3>SAWS 0.1 (beta) running on port "+str(MyPort)+"</h3>"+EndOfLine
    html=html+"</body>"+EndOfLine
    html=html+"</html>"+EndOfLine
    Return html
  else
    Return ""
  end
End Function