원문 출처 : http://stackoverflow.com/questions/18554074/is-it-possible-to-sort-items-in-fso-with-classic-asp
요점은.. 파일시스템객체를 생성후 이것을 레코드 셋에 담고
레코드 셋의 정렬 기능을 사용한 다음..
레코드 셋을 출력하면 된다..
진짜 기발하다!!
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Option Explicit %>
<%Response.ContentType = "text/xml"%>
<%Response.AddHeader "Content-Type","text/xml"%>
<songlist>
<%
Const adVarChar = 200
Const adInteger = 3
Const adDate = 7
Dim objFSO, oFolder, oFile
Dim fileCounter, objRS
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'point to a specific folder on the server to get files listing from...
Set oFolder = objFSO.GetFolder(Server.MapPath("."))
Set objFSO = Nothing
'create a disconnected recordset
Set objRS = Server.CreateObject("ADODB.Recordset")
'append proper fields
objRS.Fields.Append "Name", adVarChar, 255
objRS.Fields.Append "DateLastModified", adDate
objRS.Open
'loop through all the files found, add to the recordset
For Each oFile in oFolder.Files
objRS.AddNew
objRS.Fields("Name").Value = oFile.Name
objRS.Fields("DateLastModified").Value = oFile.DateLastModified
Next
Set oFolder=nothing
'sort and apply:
objRS.Sort = "DateLastModified DESC"
objRS.MoveFirst
fileCounter = 0
'loop through all the records:
Do Until objRS.EOF %>
<song>
<songid><%=fileCounter%></songid>
<filename><%=objRS("Name")%></filename>
<datemodified><%=objRS("DateLastModified")%></datemodified>
</song><%
fileCounter = fileCounter + 1
objRS.MoveNext()
Loop
objRS.Close
Set objRS = Nothing
%>
</songlist>
댓글 없음:
댓글 쓰기