asp如何在线查询本地机的文件?

时间:2010-06-22 21:19:00 

如何在线查询本地机的文件?

看看下面的例子,默认子目录与子虚拟目录为同一级别且名称一致,另我们使用了"http://intels.net"是为了便于显示,其中的“C:\”可改为虚拟网络目录:

<html>
<head>
<title>随风起舞之文件查询</title>
</head>
<body>
<p align="center" >
  <b><font face="宋体" color="red" size="5">
  精彩春风之文件查询系统</font></b>
</p>
<hr>
<form method="POST" action="search.asp">
  <p><font color="green">请输入要查询的目录文字:
  <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="green">查询结果:</font></p>
<%
data=request.form("search_data")
' 得到要查询的文件名称所要包含的字符串
p=search_folder(data,"http://yup.go.163.com","c:\")
' 调用函数查询目标查询目录下的所有子目录(所有子树)
%>
<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>

标签:文件,asp,目录
0
投稿

猜你喜欢

  • Mysql数据库存储过程基本语法讲解

    2024-01-20 04:46:35
  • PyQtGraph在pyqt中的应用及安装过程

    2022-02-27 17:00:14
  • PHP信号处理机制的操作代码讲解

    2023-07-14 09:26:49
  • 7个Python中的隐藏小技巧分享

    2022-06-20 22:36:14
  • 详解Python字典的操作

    2023-07-10 11:20:50
  • Python爬虫Scrapy框架IP代理的配置与调试

    2022-09-19 08:20:26
  • layui 数据表格 点击分页按钮 监听事件的实例

    2024-04-19 10:45:12
  • django如何根据现有数据库表生成model详解

    2024-01-17 02:29:21
  • 基于layPage插件实现两种分页方式浅析

    2024-05-28 15:40:53
  • python爬虫可以爬什么

    2022-05-26 01:24:31
  • mysql表分区的使用与底层原理详解

    2024-01-24 06:24:25
  • 如何基于python实现年会抽奖工具

    2022-01-28 04:24:42
  • JS调用打印方法设置页眉页脚的实例

    2024-04-22 12:45:58
  • python+matplotlib实现动态绘制图片实例代码(交互式绘图)

    2022-06-16 15:43:08
  • 实现SQL Server 原生数据从XML生成JSON数据的实例代码

    2024-01-16 01:46:03
  • python+selenium定时爬取丁香园的新型冠状病毒数据并制作出类似的地图(部署到云服务器)

    2022-12-31 16:20:14
  • innerHTML在Mozilla Firefox和Opera下执行的一个特例情况。

    2023-09-16 11:23:46
  • Python机器视觉之基于OpenCV的手势检测

    2021-06-12 10:54:11
  • 如何利用Pyecharts可视化微信好友

    2022-04-13 07:34:14
  • Python内置的HTTP协议服务器SimpleHTTPServer使用指南

    2021-11-22 08:11:12
  • asp之家 网络编程 m.aspxhome.com