<% 'impostiamo la cartella da cui leggere i file strPath = Server.MapPath("\") 'impostiamo ed apriamo il recordset Set RS = Server.CreateObject("ADODB.Recordset") RS.Fields.Append "name", 200, 255 ' adVarChar RS.Fields.Append "size", 3, 4 ' adInteger RS.Fields.Append "date", 7 ' adDate RS.Open 'recuperiamo i file Set FileObject = Server.CreateObject("Scripting.FileSystemObject") Set f = FileObject.GetFolder(strPath)
'memorizziamo il file nel recordset For Each f1 in f.Files RS.AddNew RS("name") = f1.Name RS("size") = Int(f1.Size/1000) If RS("size") = 0 Then RS("size") = 1 RS("date") = f1.DateCreated Next
Set f = Nothing Set FileObject = Nothing
'recuperiamo le azioni di ordinamento orderby = Request.QueryString("orderby") ordertype = Request.QueryString("ordertype") sort1 = "desc" sort2 = "asc" sort3 = "asc"
'prepariamo l'istruzione di ordinamento da passare 'alla proprietà Sort, nel caso non siano state 'passate azioni di ordinamento i file saranno 'ordinato per nome crescente sort = "name ASC" If orderby <> "" Then sort = orderby If ordertype = "asc" Then sort = orderby & " ASC" ElseIf ordertype = "desc" Then sort = orderby & " DESC" End If Select Case orderby Case "name" If ordertype = "desc" Then sort1 = "asc" ElseIf ordertype = "asc" Then sort1 = "desc" End If Case "size" sort1 = "asc" If ordertype = "desc" Then sort2 = "asc" ElseIf ordertype = "asc" Then sort2 = "desc" End If Case "date" sort1 = "asc" If ordertype = "desc" Then sort3 = "asc" ElseIf ordertype = "asc" Then sort3 = "desc" End If End Select End If 'ordiniamo il recordset RS.Sort = sort RS.MoveFirst 'visualizziamo il risultato a video scorrendo il nostro 'recordset Response.Write "<table>" & VBCrLf Response.Write "<tr><td><a href=""?orderby=name&ordertype=" Response.Write sort1 & """>Nome</a></td><td align=""right"">" Response.Write "<a href=""?orderby=size&ordertype=" & sort2 Response.Write """>Dimensione</a></td><td><a href=""" Response.Write "?orderby=date&ordertype=" & sort3 & """>" Response.Write "Data creazione</a></td></tr>" & VBCrLf Do While Not RS.EOF Response.Write "<tr><td>" & RS("name") & "</td><td align=""right"">" Response.Write RS("size") & " KB</td><td>" & RS("date") Response.Write "</td></tr>" & VBCrLf RS.MoveNext Loop Response.Write "</table>" & VBCrLf RS.Close Set RS = Nothing %>
|