none
How to use EnumerateFiles

    Question

  • msdn says:about EnumerateFiles:

    The EnumerateFiles and GetFiles methods differ as follows: When you use EnumerateFiles, you can start enumerating the collection of names before the whole collection is returned; when you use GetFiles, you must wait for the whole array of names to be returned before you can access the array. Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.

    How can I start using the collection before the whole collection is returned?

    The following code gives an elapsed time of more than 3 minutes for a directory with around 45000 files

    Dim TIme1, TIme2 As String

    TIme1 = TimeString

    Dim DirFiles As Generic.List(Of String) = New Generic.List(Of String)(Directory.EnumerateFiles(SourceDirectory))

    Dim NumberOfFiles As Integer

    NumberOfFiles = DirFiles.Count()

    TIme2 = TimeString

    MsgBox("Begin time " & TIme1 & "There are " & NumberOfFiles & " Photos in the Directory ." & SourceDirectory & "End Time " & TIme2)

    Can I already use entries in Dirfiles before the collection is entirely read? How?

    WHY: I try to develop a screensaver that will display RANDOM images from a directory that will grow to more than 50000 images. The screensaver should show the first image after 1 or 2 seconds. I guess I must use EnumerateFiles, or is there another way to read files randomly from a directory?

    Thanks for any useful information and suggestions.

    Kind regards

    Marc

    • Moved by litdev Monday, August 03, 2015 3:31 PM
    Thursday, July 30, 2015 3:36 AM

Answers

All replies