Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ADIR and ASORT for .NET ?
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01020162
Message ID:
01021015
Vues:
27
>>Einar,
>>
>>I need to follow the IT standard for the company, which is VB.NET at the moment. In VB.NET as far as I see, the GetFiles() allows to create a one-dimensional array and with file names only. But I need file dates to sort the list. Am I missing anything here?
>
>Yuri,
>I see. I thought GetFiles() returned a file object and not just a string. You said your current VB.NET code takes several minutes per directory. Could you post your code? Maybe I can find a way to speed it up. Are you using GetLastWriteTime()? It seems pretty snappy to me but then I only have 28 files in the directory I tested :)

Here are two approaches I tested so far:
....
ofso = CreateObject("Scripting.FileSystemObject")
.....

Sub CleanBackup(ByVal BackupDirectory)
        'erase files older than 15 days back
                If Not ofso.FolderExists(BackupDirectory) Then
            Exit Sub
        End If
        With ofso.GetFolder(BackupDirectory)
            If .Files.Count > 0 Then
                For Each oitem In .Files
                    If DateDiff(DateInterval.Day, oitem.DateCreated, Now) > 14 Then
                        oitem.delete()
                    End If
                Next
            End If
        End With
End Sub

Sub TestCleanBackup(ByVal BackupDirectory)
        'erase files older than 15 days back
        If Not System.IO.Directory.Exists(BackupDirectory) Then
            Exit Sub
        End If

        Dim aFiles() As String

        aFiles = System.IO.Directory.GetFiles(BackupDirectory, "*.*")
        For ia = 0 To aFiles.Length - 1
            If DateDiff(DateInterval.Day, System.IO.File.GetCreationTime(aFiles(ia)), Now) > 14 Then
                System.IO.File.Delete(aFiles(ia))
            End If
        Next
End Sub
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform