Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 14
  1. #1

    sort per data...

    Salve,
    ho questo script che mi elenca i file contenuti in una determinata cartella:

    <%@LANGUAGE="VBSCRIPT"%>
    <html>
    <head>
    <title>Ordini Agenti</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    <!--
    a:link {
    text-decoration: none;
    }
    a:visited {
    text-decoration: none;
    }
    a:hover {
    text-decoration: none;
    }
    a:active {
    text-decoration: none;
    }
    -->
    </style></head>

    <body text="#006699" background="">


    <font face="Arial, Helvetica, sans-serif"> <font size="2">
    <%
    Const adFilesSubFolder = 0
    Const adFiles = 1
    Const adSubFolder = 2

    Class cFolder
    Public Rs
    Public Fso
    Public Sort
    Public Filter
    Public ListType
    Public Path
    Public EnabledSize
    Public Style
    Public ColumnStyle
    Public WebServerFP
    Public ScriptName
    Private LenWebServerFP

    Private Sub Class_Initialize()
    Set fso=CreateObject("Scripting.FileSystemObject")
    Set Rs= CreateObject("ADODB.Recordset")
    EnabledSize = False
    Style = "width='95%' borderColor=#006699 style='font-family:verdana;font-size:11' border='2' cellspacing='3' "
    ColumnStyle = "align='center' bgColor='#999999' style='color:white'"
    WebServerFP = Request.ServerVariables("APPL_PHYSICAL_PATH")
    LenWebServerFP = Len(WebServerFP)
    ScriptName = Mid(Request.ServerVariables("SCRIPT_NAME"),InStrRe v(Request.ServerVariables("SCRIPT_NAME"),""))
    End Sub

    Private Sub Initialize()
    ListType = adFilesSubFolder
    Sort = Empty
    Filter = Empty
    If Rs.State=0 then
    Rs.fields.append "Name",201,255
    Rs.fields.append "DateCreated",135,-1
    Rs.fields.append "DateLastModified",135,-1
    Rs.fields.append "DateLastAccessed",135,-1
    if EnabledSize then Rs.fields.append "Size",20,-1
    Rs.fields.append "IsFolder",11,-1
    Rs.fields.append "IsHidden",11,-1
    Rs.Open
    end if
    End sub

    Private Function FpToUrl(pPath)
    FpToUrl = Replace(Mid(pPath,LenWebServerFP+1),"\","/")
    End Function

    Public Function Print()
    Dim i,f,ParentName
    ParentName = FpToUrl(fso.GetParentFolderName(Path))
    response.Write("<table " & Style &">")
    response.Write("<tr " & ColumnStyle &">")
    for each f in Rs.Fields
    Response.Write("<td>" & f.name & "</td>")
    next
    response.Write("</tr>")
    if Not Rs.eof then
    Rs.MoveFirst
    While Not Rs.Eof
    response.Write("<tr>")
    for each f in Rs.Fields
    If f.name="Name" then
    If Rs("IsFolder") then
    response.Write("<td>" & f.value & "</td>")
    else
    response.Write("<td>" & f.value &"</td>")
    end if
    else
    response.Write("<td>" & f.value & "</td>")
    end if
    next
    response.Write("</tr>")
    Rs.MoveNext
    Wend
    End if
    response.Write("</table>
    ")
    End function

    Private Function SetList(Path,TypeFile)
    Dim File,Files
    Execute "Set Files= Fso.GetFolder(Path)." & TypeFile
    for each File in Files
    rs.AddNew
    rs("Name")=File.Name
    rs("DateCreated")=File.DateCreated
    rs("DateLastModified")=File.DateLastModified
    rs("DateLastAccessed")=File.DateLastAccessed
    if EnabledSize then rs("Size") = File.Size
    rs("IsFolder")= (File.Attributes And 16) = 16
    rs("IsHidden")= (File.attributes And 2) = 2
    Rs.Update
    next
    Set Files= nothing
    end function

    Public Function Open()
    If ListType=adFilesSubFolder or ListType=adSubFolder then SetList Path,"Subfolders"
    If ListType=adFilesSubFolder or ListType=adFiles then SetList Path,"Files"
    If Not IsEmpty(Sort) then rs.sort = sort
    If Not IsEmpty(Filter) then rs.filter = filter
    End Function

    Public Function SetPath(pPath)
    Initialize()
    on error resume next
    Path = Server.MapPath(pPath)
    If Err.number<>0 then
    response.write("Errore:" & err.description):response.end
    end if
    on error goto 0
    end function

    Public Sub Close()
    On error resume next
    Rs.Close
    On error goto 0
    End Sub

    Private Sub Class_Terminate()
    Close()
    Set Rs= Nothing
    Set Fso = Nothing
    End Sub

    End Class

    Set Folder = new cFolder
    Folder.EnabledSize = True
    If Request.QueryString("Folder")="" then
    Folder.SetPath(".")
    else
    Folder.SetPath(Request.QueryString("Folder"))
    end if
    Folder.Sort = "IsFolder Desc,DateCreated"
    'Folder.Filter = "Name Like 'a*'"
    Folder.Open()
    Folder.Print()
    Folder.Close()
    Set Folder = Nothing

    %>
    </font></font></p>
    </body>
    </html>




    Qualcuno di voi può aiutarmi ad elencare i file in ordine decrescente di data di creazione, in pratica quelli più recenti in cima alla lista?

    Inoltre pensate che sia possibile scrivere le date in un modo più leggibile di quello che si può vedere nell'immagine allegata ?


    Grazie anticipate per chiunque voglia aiutarmi...
    Immagini allegate Immagini allegate

  2. #2
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,472

    Moderazione

    Le domande su ASP sono ospitate nell'apposita sezione.

    Sposto la discussione.
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

  3. #3

  4. #4
    grazie optime per la risposta,
    dove dovrei inserire il ".sort" per farlo funzionare ?

  5. #5
    quando hai finito di caricare il recordset (rs) lo sorti con rs.sort

  6. #6

    parzialmente risolto !!

    Ok l'ordinamento l'ho risolto!

    Ora mi rimane da sistemare le date in modo che si leggano correttamente: invece di vedere quei "/01/aa" dovrei vedere "23/01/07" o comunque qualcosa di comprensibile.

    Ho provato a sostituire un po' di cifre al posto di:

    Rs.fields.append "DateCreated",135,-1

    ma mi da errore oppure non cambia niente.
    Qualcuno di voi conosce un modo per ovviare all'inconveniente?

    Grazie 1k...

  7. #7

    up...

    non c'è nessuno in grado di risolvere il problema ?

  8. #8
    Utente di HTML.it L'avatar di Lak3d
    Registrato dal
    Aug 2006
    Messaggi
    1,031
    potevi anche risolvere in fase di estrazione con una query...
    Per quanto riguarda le date: perchè vengono scritte in quel formato? dagli un occhiata quando le prendi col file system object...

  9. #9

    è proprio il perchè che non so...

    Non ho idea del perchè le stampi in quel modo.
    Se controllo i dettagli dei file hanno date corrette, come puoi vedere dall'immagine allegata.
    Immagini allegate Immagini allegate

  10. #10

    risultato...

    e questo invece è come stampa la data degli stessi file:
    Immagini allegate Immagini allegate

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.