如何编写一个基于WEB的文件查询系统?

来源:asp之家 时间:2009-11-08 18:55:00 

 这个例子可作为一个模式,在你需要的时候套用。

<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<html>
<head>
<title>WEB查询系统 - Aspxhome.com</title>
</head>
<body>
<p align="center" ><b><font face="宋体" color="#A00BE1" size="5">
精彩春风WEB文件查询系统</font></b></p>
<hr>
<form method="POST" action="search.asp">
<p><font color="#A00BE1">请输入查询的目录文字:<input type="text" 
name="search_data" size="20"><input type="submit" value="查询" 
name="B1"><input type="reset" value="重写" name="B2"></font>
</p>
</form>
<hr>
<p style="text-indent: 0; word-spacing: 0; line-height: 100%; 
margin: 0"><font color="#A00BE1">查询结果:</font></p>
<%
data=request.form("search_data")
' 获取符合条件的字符串
p=search_folder(data,"http://intels/cgi-bin","c:\shanliangrizi\wwwroot\cgi-
bin")
' 查询目录下的所有子目录,包括查询的字符串、目标的虚拟绝对路径和真实绝对路径
%>
<script language="vbscript" RUNAT=SERVER>
function search_folder(search_data,v_path,c_path)
dim file_system,cur_folder,sub_folders,sub_files
' 目录检索函数
if not isempty(search_data) and len(search_data)>0 then
' 确定查询字符串有效非空
set file_system=createobject("scripting.filesystemobject")
' 建立文件系统对象 
set cur_folder=file_system.getfolder(c_path)
' 建立当前目录对象
set sub_folders=cur_folder.subfolders
' 建立当前目录的子目录对象集合
for each each_sub_folder in sub_folders
' 遍历子目录集合
if each_sub_folder.attributes=16 then
' 确定子目录属性为普通
sub_v_path=v_path&"/"&each_sub_folder.name
sub_c_path=c_path&"\"&each_sub_folder.name
' 得到当前子目录的虚拟绝对路径与真实绝对路径
p=search_file(search_data,sub_v_path,sub_c_path)
' 进行字符串匹配检索
p=search_folder(search_data,sub_v_path,sub_c_path)
' 递归检索下一级目录
end if
next
set each_sub_folder=nothing
set sub_folders=nothing
set cur_folder=nothing
set file_system=nothing
' 清除服务器端对象
end if 
end function
function search_file(search_data,v_path,c_path)
dim file_system,sub_files,sub_file_v_path,sub_out_v_path
' 文件匹配检索函数
if not isempty(c_path) then
' 确认路径不为空
set file_system=createobject("scripting.filesystemobject")
set cur_folder=file_system.getfolder(c_path)
set sub_files=cur_folder.files
' 建立检索目录下的文件对象集合
for each each_file in sub_files
' 遍历文件对象集合
if instr(each_file.name,search_data)<>0 then
' 匹配字符串和文件名
sub_file_v_path=v_path&"/"&each_file.name
' 建立有效链接,输出匹配文件
sub_out_v_path=Replace(sub_file_v_path," ","%20")
' 替换空格
response.write("<p><a href="&sub_out_v_path&">"&sub_file_v_path&"</a>")
end if 
next
set sub_out_v_path=nothing
set sub_file_v_path=nothing
set each_file=nothing
set sub_files=nothing
set file_system=nothing
end if
end function
</script>
<hr>
</body>
</html>

 

标签:文件,查询,系统,web
0
投稿

猜你喜欢

  • Sql语句优化注意

    2009-10-31 13:15:00
  • 详解SQL Server中数据库快照工作原理

    2009-01-21 14:18:00
  • 发散后的期望

    2008-07-31 18:32:00
  • SQL Server命令行导数据的2种方式

    2010-07-26 14:48:00
  • swfupload上传使用代码说明ASP版

    2011-11-27 09:34:32
  • 当标题不能显示完整的时候

    2007-11-20 13:23:00
  • 不同分辨率下的自适用宽度

    2008-11-24 12:58:00
  • oracle10g 数据备份与导入

    2009-06-10 18:21:00
  • 文章关键字替换带链接需要注意的两个问题

    2010-02-25 12:18:00
  • 改善登陆界面的用户体验: 自动聚焦表单

    2009-12-09 16:13:00
  • asp小偷程序原理和简单示例

    2007-11-05 17:12:00
  • window.location.hash的应用及浏览器的支持测试

    2009-07-07 11:52:00
  • True or False,明明白白你的If语句流程

    2008-01-25 19:00:00
  • 流行WEB开发语言比较之ASP篇

    2007-12-23 17:23:00
  • 30个最常用css选择器解析

    2011-06-16 20:36:37
  • 设计之外随谈

    2009-06-16 14:38:00
  • MySQL安全性指南 (1)(转)

    2010-07-27 12:49:00
  • 我所钟爱的HTML5资源

    2010-07-23 09:25:00
  • “Unable to read local eventlog (reason:事件日志文件已在读取时间更改)”解决办法

    2009-08-27 13:12:00
  • 不安全的js写法

    2009-09-16 14:26:00
  • asp之家 网络编程 m.aspxhome.com