当前位置: 首页 > 图文教程 > 网络编程 > 编程10000问 > 如何在线查询本地机的文件?

编程10000问
如何实现在下拉菜单里输入文字?
如何使用数组来显示下拉菜单?
如何用下拉列表显示数据库里的内容?
如何在读取Excel文件时创建列表的下拉菜单?
如何制作关联的下拉菜单?
如何测试字符串的长度?
如何验证字符串是否包含有效字符?
如何检测字符串出现的次数?
如何准确地获得一个整数?
如何编写一个小数转换分数的函数?
如何把一长串数字分位显示?
如何正确显示数据库里同时存在的GB码和BIG5码?
如何实现人民币的大写转换?
怎样给文件加密最安全?
如何用Access加密页面?
为什么用磁盘序列号加密过的代码不能被复制安装?
如何根据用户银行帐户余额的多少进行显式的提交或终止?
如何获知所有的Cookie?
如何提示用户打开Cookie?
如何刪除客户端的Cookies?

编程10000问 中的 如何在线查询本地机的文件?


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 30 ::
收藏到网摘: n/a

<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>

[1]