Quantcast
Channel: Xojo Programming Forum - Latest topics
Viewing all articles
Browse latest Browse all 3773

What is the fastest method to get the number of files in a folder?

$
0
0

What is the fastest method to get the number of files in a folder?
Xojo method:

Var folder As FolderItem = SpecialFolder.Desktop.Child("FolderName")
If folder <> Nil And folder.Exists And folder.IsFolder Then
    Var count As Integer = 0
    Var item As FolderItem
    Var iterator As FolderItemIterator = folder.Children
    While iterator.HasNextItem
        item = iterator.NextItem
        If item <> Nil Then
            count = count + 1
        End If
    Wend
    MessageBox("Number of files : " + count.ToString)
End If

Shell method:

Var sh As New Shell
sh.Execute("find '/chemin/vers/dossier' -type f | wc -l")
Var result As String = sh.Result.Trim
MessageBox("Number of files : " + result)

MBS method:

Var folder As New FolderItemMBS(SpecialFolder.Desktop.Child("NomDossier"))
If folder <> Nil And folder.Exists And folder.Directory Then
    Var files() As FolderItemMBS = folder.Children
    MessageBox("Number of files : " + files.Count.ToString)
End If

Thanks

7 posts - 7 participants

Read full topic


Viewing all articles
Browse latest Browse all 3773

Trending Articles