[ASP技巧]巧给FSO文件夹列表内容排序-VeryGood
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
自己写排序算法十分繁琐,而且不够灵活,百度搜索“ASP 文件夹排序”搜到的结果可以100%视为垃圾。本文推荐一种最小代价的做法。 '定义获取排序文件列表的函数 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 = "Name ASC, 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 "文件信息:" & rs("Name") & " │ " & rs("Type") rs.MoveNext Wend rs.Close Set rs = Nothing 该文章在 2017/12/20 15:20:17 编辑过 |
关键字查询
相关文章
正在查询... |