日期:2010-01-19  浏览次数:20866 次

读取文件中所有文件的总数,并且可根据需要修改文件名.

代码如下:
<%
On Error Resume Next
set fso = CreateObject("Scripting.FileSystemObject")
Set uploadfolder = fso.GetFolder (server.mappath("img"))’img 为指定的文件夹
set allfiles = uploadfolder.Files
if isempty(request.querystring("act")) then
i=1
response.Write"<table width=""620"" border=""1"" cellspacing=""0"" cellpadding=""5"" align=""center"">"
for each fileitem in allfiles
sFileName = fileitem.Name
response.Write"<tr>"
response.Write"<td width=""50"" align=""center"">"&i&"</td>"
response.Write"<td width=""450"">"&sFileName&"</td>"
response.Write"<td width=""120"" align=""center""><a href=""javascript:;"" onClick=""javascript:window.open(’?act=edit&filename="&sFileName&"’,’newwindow’,’height=300, width=550, top=250, left=250, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no’)"">编辑文本文件</a></td>"
response.Write"</tr>"
i=i+1
next
response.Write"</table>"
response.Write"文件总数:"&(i-1)
end if

if request("act")="Savefilename" then
set f=fso.GetFile(server.MapPath("img/"&request("ofn")))
f.Name =request("filestr")
set f=nothing
end if
if request.querystring("act")="edit" then
%>
<table align="center" border="1" width="100%" height="100%" cellspacing="0" cellpadding="3" bordercolor="#6595d6">
<form name="form1" method="post" action="?act=Savefilename&ofn=<%=request("filename")%>">
<tr><th>编辑文本文件</th>
</tr>
<tr><td>文件名:
<textarea name="filestr" style="width:98%;height:100%;"><%=request("filename") %></textarea></td></tr>
<tr height="25"><td align="center">
<input type="submit" value="保存"><input type="button" value="关闭" onClick="window.close();">
</td></tr>
</form>
</table>
<%
end if
%>