ASP遍历文件问题

ASP遍历文件问题,第1张

<%

sub bianli(path)

dim fso

dim objFolder

dim objSubFolder

dim objFile

set fso=server.CreateObject("scripting.filesystemobject")

on error resume next

set objFolder=fso.GetFolder(path)

for each objFile in objFolder.Files

Response.Write path &"\\" &objFile.name &"<br>---"

next

Response.Write "<p>"

for each objSubFolder in objFolder.Subfolders

nowpath=path &"\\" &objSubFolder.name

Response.Write nowpath &"<br>"

bianli nowpath

next

set objFolder=nothing

set fso=nothing

end sub

bianli "D:\shuaigua\56bohai"

%>

看明白没有?你要先显示当前文让衡羡件夹(注意当前)中的文件集合,再遍历文件夹中的子文坦拍件夹集合。而你的做法则是显示子文件夹(注意子字)中的文件拦盯集合,再去遍历子文件夹集合,这样的话一开始的那个文件夹(即D:\shuaigua\56bohai)的文件就无法显示了!

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<伏孙title>Document</title>

</head>

<body><%

'配置目录

filepath ="e:\"

'关键字

keyword ="aaa"

'获取扩展名

Function getExt(exttext)

If inStr(exttext,".")>0 then

getExt = LCase(mid(exttext,InstrRev(exttext,".")+1))

Else

getExt = ""

End If

End Function

'获取所有文本文件

Function alltxtfile(path)

Dim tmp:tmp=""

Set fso=server.CreateObject("scripting.filesystemobject")

Set objFolder=fso.GetFolder(path)

For Each objFile In objFolder.Files

If getExt(objFile.name)="txt" then

Set txt=fso.opentextfile(objFile.path,1,true)

If not txt.atendofstream Then

con=txt.readall

tmp= tmp&",{""filename"":"""&objFile.name&""",""filecon"":"""明颂&con&""",""keycount"":"""&ubound(split(con,keyword))&"""}"

End If

txt.Close

Set txt=Nothing

End If

next

Set objFolder=Nothing

Set fso=Nothing

alltxtfile = "["激厅郑&Mid(tmp,2)&"]"

End Function

response.write alltxtfile(filepath)

%>

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/12116742.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存