asp如何遍历目录下的文件? 如何统计被点击的次数

CrisZc 2005-05-19 09:10:31
如何实现 遍历?底下这个就是,但是如何遍历 指定目录 下呢?
例如如何 遍历 网站下的一个 doc 文件夹,在页面显示这个文件夹下的所有文件<%
sub ListFolderContents(path)

dim fs, folder, file, item, url

set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder(path)

'Display the target folder and info.

Response.Write("<li><b>" & folder.Name & "</b> - " & folder.Files.Count & " files, ")
if folder.SubFolders.Count > 0 then
Response.Write(folder.SubFolders.Count & " directories, ")
end if
Response.Write(Round(folder.Size / 1024) & " KB total." & vbCrLf)

Response.Write("<ul>" & vbCrLf)

'Display a list of sub folders.

for each item in folder.SubFolders
ListFolderContents(item.Path)
next

'Display a list of files.

for each item in folder.Files
url = MapURL(item.path)
Response.Write("<li><a href=""" & url & """>" & item.Name & "</a> - " & item.Size & " bytes, " _
& "last modified on " & item.DateLastModified & "." & "</li>" & vbCrLf)
next

Response.Write("</ul>" & vbCrLf)

Response.Write("</li>" & vbCrLf)

end sub

function MapURL(path)

dim rootPath, url

'Convert a physical file path to a URL for hypertext links.

rootPath = Server.MapPath("/")
url = Right(path, Len(path) - Len(rootPath))
MapURL = Replace(url, "\", "/")

end function %>


2. 如何统计 阅读次数 ?

就是如何统计某文件被点击了多少次
...全文
336 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
huing 2005-05-24
  • 打赏
  • 举报
回复
我的也出现了这种 情况,寻找解决的办法中。。
CrisZc 2005-05-23
  • 打赏
  • 举报
回复
还是无法显示,我的是 xp 系统(sp2),
一到 这里
set fso = server.CreateObject("Scripting.FileSystemObject")就不显示了。
是不是没有打开 fso 权限?

好像在哪里看到过说 win2000是默认打开了fso ,xp默认关闭,具体我在哪里打开这个权限阿。
huing 2005-05-23
  • 打赏
  • 举报
回复
mark
leinchu 2005-05-20
  • 打赏
  • 举报
回复
<script language=javascript runat="server">
var fso,pfdn;
fso = new ActiveXObject("Scripting.FileSystemObject");
function getfolders(folderspec){
var f, fc, s,folderspec;
f = fso.GetFolder(folderspec);
fc = new Enumerator(f.SubFolders);
for (; !fc.atEnd(); fc.moveNext())
{
afd=fc.item();
document.write("<font color=000099>"+afd+"</font><br>");
getfiles(afd);
getfolders(afd);
}

}

function getfiles(folderspec){
f = fso.GetFolder(folderspec);
fc = new Enumerator(f.files);
s = "";
for (; !fc.atEnd(); fc.moveNext())
{
afl=fc.item();
s+=afl+"    "+Math.round(afl.size/1024)+" K<br>";
}
document.write(s);
}
getfolders("e:\web");
</script>

<script language=vbscript runat=server>
set fso = server.CreateObject("Scripting.FileSystemObject")
function getfolders(folderspec)
set f = fso.GetFolder(folderspec)
set fds=f.subfolders
for each afd in fds
response.Write "<font color=000099>"+afd.name+"</font><br>"
getfiles(afd)
getfolders(afd)
next

end function

function getfiles(folderspec)
set f = fso.GetFolder(folderspec)
s = ""
set fc=f.files
for each afl in fc
s=afl.name+"    "+cstr(int(afl.size/1024))+" K<br>"
response.Write s
next
end function
getfolders("e:\web")
</script>

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="Connections/conn.asp"-->
<%

if application("visit_ref")="" then
'response.Write "visit_ref="" """
set rsc=Server.CreateObject("Adodb.Recordset")
rsc.open "select top 1 pdate from Visit_rec order by pdate",conn,1,3
application("visit_ref")=now
if not (rsc.eof and rsc.bof) then
'response.Write "rsc find record"
if datediff("d",rsc("pdate"),now)>0 then
'response.Write "datediff(""d"",now,rsc(""pdate""))>0"
rsc.close
rsc.open "SELECT COUNT(LEFT(pdate, 10)) AS Expr2, LEFT(pdate, 10) AS Expr1 FROM Visit_rec GROUP BY LEFT(pdate, 10)",conn,1,3
while not rsc.eof
conn.execute "insert into Visit_total(pdate,num) values('"&rsc("Expr1")&"','"&rsc("Expr2")&"')"
rsc.movenext
wend
conn.execute "delete from visit_rec"
'else
'response.Write rsc("pdate")&datediff("d",rsc("pdate"),now)
end if
end if
rsc.close
set rsc=nothing
else
'response.Write "app has value"
if datediff("d",application("visit_ref"),now)>0 then
application("visit_ref")=now
set rsc=Server.CreateObject("Adodb.Recordset")
rsc.open "SELECT COUNT(*) AS Expr2, LEFT(pdate, 10) AS Expr1 FROM Visit_rec GROUP BY LEFT(pdate, 10)",conn,1,3
if not rsc.eof then
conn.execute "insert into Visit_total(pdate,num) values('"&rsc("Expr1")&"','"&rsc("Expr2")&"')"
end if
conn.execute "delete from visit_rec"
rsc.close
set rsc=nothing
end if
end if
set rs= Server.CreateObject("Adodb.Recordset")
rs.open "select id from Visit_rec where ip='"&request.ServerVariables("REMOTE_ADDR")&"'",conn,1,3
if rs.eof and rs.bof then
conn.execute "insert into Visit_rec(ip,pdate,rfr) values('"&request.ServerVariables("REMOTE_ADDR")&"','"&now&"','"&left(request.QueryString("rfr"),50)&"')"
end if
rs.close
set rs=nothing

set rs= Server.CreateObject("Adodb.Recordset")
rs.open "select count(id) as ct from Visit_rec",conn,1,3
if not (rs.eof and rs.bof) then
ct=rs("ct")
else
ct=1
end if
rs.close
set rs=nothing
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>访问记录</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body topmargin="0" leftmargin="0">
<font color="#FFFFFF"><%= ct %></font>
</body>
</html>
<%
conn.close
%>
FIREGUNS 2005-05-20
  • 打赏
  • 举报
回复
<%
lujing=("pic/") '这里输入文件路径~
path=Server.MapPath(""&lujing&"")
Set fso = CreateObject("Scripting.FileSystemObject")
set fd=FSO.GetFolder(path)
count=fd.files.count-1
redim fileinfo(count,1)
i=0
for each file in fd.files
fileinfo(i,0)=file.name
fileinfo(i,1)=file.DateCreated
i=i+1
next
for i=0 to count-1
for j=i+1 to count
if cdate(fileinfo(i,1))<cdate(fileinfo(j,1)) then

tmpfile=fileinfo(i,0)

fileinfo(i,0)=fileinfo(j,0)
fileinfo(j,1)=tmpdate
fileinfo(j,0)=tmpfile
end if
next
next
temp="<marquee onMouseOver=this.stop() onMouseOut=this.start() border=0 align=middle scrollamount=1 direction=l scrolldelay=56 eftbehavior=scroll width=100% height=""100%"">"
for i=0 to count
temp=temp &"<a href="""&lujing&""&fileinfo(i,0)&""" target=""_blank""><img src="""&lujing&""& fileinfo(i,0) &""" border=""0"" width=""179"" height=""128""></a> "
next
temp=temp&"</marquee>"
response.write temp
set fd=nothing
Set fso =nothing
%>



不知道你要的是不是这样的。。
seavoher 2005-05-20
  • 打赏
  • 举报
回复
只能建立一个数据库,然后用来统计访问的次数
huing 2005-05-20
  • 打赏
  • 举报
回复
up
CrisZc 2005-05-19
  • 打赏
  • 举报
回复
up
CrisZc 2005-05-19
  • 打赏
  • 举报
回复
1。我想在一个表格里显示所有文件啊
2。要用相对路径
jarraytan 2005-05-19
  • 打赏
  • 举报
回复
<% dim fso,f,fo,act,p
set fso=server.CreateObject("scripting.filesystemobject")
set fo=fso.getfolder("G:\Downloads\")
for each f in fo.files
fso.deletefile(f.path) '删除文件
next
end if
set fso=nothing
%>
CrisZc 2005-05-19
  • 打赏
  • 举报
回复
错误类型:
Microsoft VBScript 编译器错误 (0x800A0408)
无效字符
文件 = "doc/" & myfile.name
zysoft17 2005-05-19
  • 打赏
  • 举报
回复
set ObjFileSys = Server.CreateObject("Scripting.FileSystemObject")
set MyFolder = ObjFileSys.GetFolder(Server.MapPath("doc/"))
set MyFiles = MyFolder.Files
for each myfile in MyFiles
str = mid(myfile,instrrev(myfile,".")+1)
if (str = "doc") then
文件 = "doc/" & myfile.name
end if
next
CrisZc 2005-05-19
  • 打赏
  • 举报
回复
up
huing 2005-05-19
  • 打赏
  • 举报
回复
up

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧