Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 16

Discussione: Ordine files con FSO

  1. #1

    Ordine files con FSO

    Qualcuno di voi ha gia ordinato secondo un criterio prestabilito, i files di una directory, letti utilizzando il File System Object ?

  2. #2
    non si può. devi caricare i files in un recordset disconnesso e poi ordinarlo con sort. cerca nel forum, ne abbiamo parlato spesso.

  3. #3
    Grazie Opti, si ho letto qualcosa gogooooolando un po ma non ho approfondito.

    Avevo trovato questo ma non mi fa impazzire, hai qualche link a qualche risorsa che io possa leggere ?

  4. #4
    in effetti è una schifezza. cerca nel forum quelli fatti con il recordset disconnesso

  5. #5

  6. #6
    esattamente ciò che ti suggerii.

  7. #7
    Fantastico, ci lavoro su perchè mi piacerebbe creare un ordine random, idee suggerimenti, consigli, noccioline, patatine, coccobello ?


  8. #8
    è un comune recordset, puoi riordinarlo come più ti aggrada.

  9. #9
    Visto, visto, grazie, appena ho finito lo posto.

  10. #10
    Eccolo:

    codice:
    <%
    '**********
    'kc_fsoFiles
    'Purpose:
    ' 1. To create a recordset using the FSO object and ADODB
    ' 2. Allows you to exclude files from the recordset if needed
    'Use:
    ' 1. Call the function when you're ready to open the recordset
    ' and output it onto the page.
    ' example:
    ' Dim rsFSO, strPath
    ' strPath = Server.MapPath("\PlayGround\FSO\Stuff\")
    ' Set rsFSO = kc_fsoFiles(strPath, "_")
    ' The "_" will exclude all files beginning with 
    ' an underscore 
    '**********
    Function kc_fsoFiles(theFolder, Exclude)
    Dim rsFSO, objFSO, objFolder, File
      Const adInteger = 3
      Const adDate = 7
      Const adVarChar = 200
      
      'create an ADODB.Recordset and call it rsFSO
      Set rsFSO = Server.CreateObject("ADODB.Recordset")
      
      'Open the FSO object
      Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
      
      'go get the folder to output it's contents
      Set objFolder = objFSO.GetFolder(theFolder)
      
      'Now get rid of the objFSO since we're done with it.
      Set objFSO = Nothing
      
      'create the various rows of the recordset
      With rsFSO.Fields
        .Append "Name", adVarChar, 200
        .Append "Type", adVarChar, 200
        .Append "DateCreated", adDate
        .Append "DateLastAccessed", adDate
        .Append "DateLastModified", adDate
        .Append "Size", adInteger
        .Append "TotalFileCount", adInteger
      End With
      rsFSO.Open()
    	
      'Now let's find all the files in the folder
      For Each File In objFolder.Files
    	
        'hide any file that begins with the character to exclude
        If (Left(File.Name, 1)) <> Exclude Then 
          rsFSO.AddNew
          rsFSO("Name") = File.Name
          rsFSO("Type") = File.Type
          rsFSO("DateCreated") = File.DateCreated
          rsFSO("DateLastAccessed") = File.DateLastAccessed
          rsFSO("DateLastModified") = File.DateLastModified
          rsFSO("Size") = File.Size
          rsFSO.Update
        End If
    
      Next
    	
      'And finally, let's declare how we want the files 
      'sorted on the page. In this example, we are sorting 
      'by File Type in descending order,
      'then by Name in an ascending order.
      'rsFSO.Sort = "Type DESC, Size ASC "
       rsFSO.Sort = "Name Desc"
    
      'Now get out of the objFolder since we're done with it.
      Set objFolder = Nothing
    
      'now make sure we are at the beginning of the recordset
      'not necessarily needed, but let's do it just to be sure.
      rsFSO.MoveFirst()
      Set kc_fsoFiles = rsFSO
    	
    End Function
    
    'Now let's call the function and open the recordset on the page
    'the folder we will be displaying
    Dim strFolder : strFolder = Server.MapPath("brandsoi/public/images_mido/")
    
    'the actual recordset we will be creating with the kc_fsoFiles function
    Dim rsFSO 'now let's call the function and open the recordset
    
    'we will exclude all files beginning with a "_"
    Set rsFSO = kc_fsoFiles(strFolder, "_")
    
    
    'Gestisco l'estensione del file
    strExt = ".jpg"
    
    'now we'll create a loop and start displaying the folder
    'contents with our recordset. Of course, this is just a
    'simple example and not very well formatted, i.e., not in
    'a table, but it gets the point across on how you can
    'ouput the recordset on the page.
      While Not rsFSO.EOF
    %>  
    
    <% if Right(rsFSO("Name").Value, Len(strExt)) = strExt then %>
    
    <%= rsFSO("Name").Value %>
    
    
    <% end if %>
    
    <%
      'and let's move to the next record
         rsFso.MoveNext()
       Wend
      
      'finally, close out the recordset
      rsFSO.close()
      Set rsFSO = Nothing
    %>
    Ho aggiunto solo l'estensione del file, poichè mi interessa leggere il contenuto di una cartellina di immagini e fin qui tutto ok.

    Resta il problema che il criterio dell'ordine lo inserisco qui

    codice:
       rsFSO.Sort = "Name Desc"
    Ma se lo volessi random ?

    se scrivo

    codice:
       rsFSO.Sort = "Name rand() limit 5"
    Ottengo:

    Tipo di errore:
    ADODB.Recordset (0x800A0BB9)
    Gli argomenti non sono di tipo valido, non sono compresi nell'intervallo consentito o sono in conflitto.
    /ordina_files_fso.asp, line 69

    :master:

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.