2015년 11월 27일 금요일

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>

댓글 없음:

댓글 쓰기

[낯선] 2025.10.11 인천 노크 공연

  Live at @인천노크 on 2025.10.11 Set List 1. 디어클라우드 - 얼음요새 Covered by 낯선 2. 낯선 - Misty Dive 3. 솔루션스 - 청춘 Covered by 낯선 4. 낯선 - Not Your Fault...