[ASP技巧]巧給FSO文件夾列表內(nèi)容排序-VeryGood
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
自己寫排序算法十分繁瑣,而且不夠靈活,百度搜索“ASP 文件夾排序”搜到的結(jié)果可以100%視為垃圾。本文推薦一種最小代價(jià)的做法。 '定義獲取排序文件列表的函數(shù) 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 '設(shè)置排序規(guī)則:按名稱排序 rs.Sort = "Name ASC" ''設(shè)置排序規(guī)則:依次按文件大小倒序,按修改日期倒序 'rs.Sort = "Name ASC, Size DESC, DateLastModified DESC" rs.MoveFirst Set folder = Nothing Set getSortedFiles = rs End Function '調(diào)用函數(shù)并輸出結(jié)果集
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 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |