First create a program on the server side to generate an XML file to return to the client, (getfolder.asp)
<%
' Written by Linzhang Chen, 2003-4-20
' Reprint please indicate the source and retain this copyright information
Response.Write "<?xml version=" "1.0" "encoding=" "GB2312" "?>" &CHR (13)
Response.Write "<mediafile>" &CHR (13)
Folders=request ("folder")
If folders= "/" Then
Folders= ""
End If
Dim count
Count=0
Folders=replace (folders, "..", "")
Basefolder= ". /media/"' Reference to the folder path
Newfolder=basefolder&folders
Set FSO =server. CreateObject ("Scripting.FileSystemObject")
Set F=fso.getfolder (Server.MapPath (NewFolder))
Set Sf=f.subfolders
For each FD in SF ' returns the list of folders below the specified path
Response.Write "<file>" &CHR (13)
Response.Write "<ftype>folder</ftype>" &CHR (13)
Response.Write "<fname>" &fd.name& "</fname>" &CHR (13)
Response.Write "</file>" &CHR (13)
Count=count+1
Next
Set sf=nothing
Set Ff=f.files
For each fi in FF
Fname=fi.name
If InStr ("Asf,wma,wmv", LCase (Mid (Fname,instrrev (fname, ".") +1)) >0 Then ' set the file type to allow return, prevent source leakage
Response.Write "<file>" &CHR (13)
Response.Write "<ftype>file</ftype>" &CHR (13)
Response.Write "<fname>" &fname& "</fname>" &CHR (13)
Response.Write "</file>" &CHR (13)
Count=count+1
End If
Next
' If there is no file in the directory, send an empty element
If Count=0 Then
Response.Write "<file>" &CHR (13)
Response.Write "<ftype>empty</ftype>" &CHR (13)
Response.Write "<fname>0</fname>" &CHR (13)
Response.Write "</file>" &CHR (13)
End If
Response.Write "</mediafile>"
Set ff=nothing
Set f=nothing
Set fso=nothing
%>