Search these areas:
Help
Support Forums
Product Info



-Introduction
-DataWeb: What's New
-Creating an Application
-The DataWeb Designer
-Application Management
-Data Tables
-Data Tables
-Views
-Templates
-Components
-Data Analysis
-Members
-Security
-Importing
-Exporting
-FTP
-JavaScript
-Object Model
-Full-Text Search
-Domain and Email Hosting
-HotBlock Modules
-Account Management
-Glossary
-New Responsive UI Module





DataWeb Help
Support Forums
Tutorial
Script Library
Knowledge Base

Home > Support

Script Library

  Script to do a simple directory listing (like some web servers do)
 
  chubbard posted this script:
  // showdir - show a directory listing on a westside directory
//
//   If you do something like http://somedomain.com/somedir and there's no file there
// and the permissions are right, and the moon is blue, you'll often get a directory
// listing. Westside webs don't have this default behaviour, so this script provides it.
//   This script does the same thing for a westside web. It looks prettier, but you
// still need a default.view file in each dir, though it can be really short,
// e.g., assuming you save the script in /util.ws, create a view file in the target
// dir with the contents:
/*
------ default.view starts here
<html>
<head>
<link rel="stylesheet" href="/default.css" type="text/css" />
<ws:viewinfo version="0.41" masterpage="/master.view" modifiedby="mike[mike@westside.com]" />
<title>index</title></head>
<body bgcolor="#FFFFFF">
#classes.import("/util.ws").showdir()#
</body>
</html>
------ default.view ends here
*/
// actual function starts here
// depending on your web permissions you may not want the asadmin permission below

public asadmin function showdir()
{
// first find the current dir by opening the URI file requested and
// then getting its folder

  var uri = request.getRequestURI();
  var oFile = File(uri);
  var sPath = oFile.getFolderPath();

// let's use a table rather than <pre>

<ws:tags>
<h3>Directory for <%= sPath %></h3>
<table>
<tr>
<th>Filename</th><th>Size</th><th>Created</th><th>Modified</th>
</tr>
</ws:tags>

// now get all the filenames and write them out

  var aFiles = Folder.create(sPath).getFileNames();
  for (var i = 0; i < aFiles.length; i++)
  {
    var oFile = File(sPath + aFiles[i]);
    var sClass = (1 == i % 2) ? "ws-data-td" : "ws-data-alt-td";
    <ws:tags>
    <tr class="<%= sClass %>">
    <td><a href='<%= aFiles[i] %>'><b><%= aFiles[i] %></b></a></td>
    <td align="right"><%= oFile.getSize() %></td>
    <td><%= oFile.getDateCreated() %></td>
    <td><%= oFile.getDateModified() %></td>
    </tr>
    </ws:tags>
  }


<ws:tags>
</table>
<p />
<p>Total of <%= aFiles.length %> files</p>
</ws:tags>
return "";
}
 
Affiliate | Partner | Terms of Use | Privacy Policy | Contact Us | Pricing | Bring DataWeb In-House    
DataWeb, 720 North 10th Street, A #145, Renton, Washington 98057 *425-583-5970* Fax 484-770-4706* Email Us