一个读取文件和子目录列表的程序

王朝other·作者佚名  2006-12-16
窄屏简体版  字體: |||超大  

<%@ page language=javascript %><html>

<!-- dir.jsp

-- Creates a page recursively listing all subdirectories and files.

-->

<head><title>Directory Listing</title></head>

<body bgcolor=#ffffff>

<h1>Directory Listing</h1>

<%

//

// Resin file I/O roughly follows java.io with the exceptions:

// 1) All filenames are urls using '/' as the filename separator.

// 2) The myriad stream classes, readers, and writers are coalesced

// into a single stream object.

//

// This function recursively lists the directory contents.

//

// Example:

//

// top

// <ul>

// <li>sub1

// <li>sub2

// <ul>

// <li>subsub

// </ul>

// </ul>

//

function readdir(path)

{

out.writeln(path.path.split('/').reverse()[0]);

if (path.isDirectory()) {

out.writeln("<ul>");

for (file in path.list()) {

out.write("<li>");

readdir(path(file));

}

out.writeln("</ul>");

}

}

readdir(File("data"));

%>

</body>

</html>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航