[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 編輯過 |
關鍵字查詢
相關文章
正在查詢... |