[ASP技巧] 巧给FSO文件夹列表内容排序(2)
Response.Write "<p>" & rs("Name") & " | " & rs("Type") & "</p>"
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
'定义获取排序文件列表的函数
Function getSortedFiles(folderPath)
Dim rs, fso, folder, File
Const adInteger = 3
Const adDate = 7
Const adVarChar = 200
Set rs = Server.CreateObject("ADODB.Recordset")
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(folderPath)
Set fso = Nothing
With rs.Fields
.Append "Name", adVarChar, 200
.Append "Type", adVarChar, 200
.Append "DateCreated", adDate
.Append "DateLastAccessed", adDate
.Append "DateLastModified", adDate
.Append "Size", adInteger
.Append "TotalFileCount", adInteger
End With
rs.Open
For Each File In folder.Files
rs.AddNew
rs("Name") = File.Name
rs("Type") = File.Type
rs("DateCreated") = File.DateCreated
rs("DateLastAccessed") = File.DateLastAccessed
rs("DateLastModified") = File.DateLastModified
rs("Size") = File.Size
rs.Update
Next
'设置排序规则:按名称排序
rs.Sort = "Name ASC"
''设置排序规则:依次按文件大小倒序,按修改日期倒序
'rs.Sort = "Size DESC, DateLastModified DESC"
rs.MoveFirst
Set folder = Nothing
Set getSortedFiles = rs
End Function
'调用函数并输出结果集
Dim rs
Set rs = getSortedFiles( Server.MapPath("/") )
While Not rs.EOF
Response.Write "<p>" & rs("Name") & " | " & rs("Type") & "</p>"
rs.MoveNext
相关新闻>>
- 发表评论
-
- 最新评论 更多>>