下面的这个函数实现的功能是列出某文件夹下的所有文件,以文件名字母排序,先数字后字母再到中文。
<%
Function ShowFileList(folderspec)
Dim fso, f, f1, fc, rs, s
const adVarChar = 200
set rs = Server.createobject("adodb.recordset")
rs.fields.append "myField", adVarChar, 255
rs.open
Set fso = server.CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
rs.addnew array("myField"), array(f1.name)
Next
rs.sort = "myField ASC" 'use "myField DESC" for reverse order
rs.moveFirst
do until rs.eof
s = s & rs.fields("myField") & "<BR>"
rs.moveNext
loop
rs.close
set rs=nothing
set fso=nothing
ShowFileList = s
End Function
'列出当前文件夹下的所有文件
Response.write ShowFileList(Server.MapPath("."))
'列出imges文件下的所有文件
Response.write ShowFileList(Server.MapPath("images/"))
%>