dcsimg
Results 1 to 3 of 3
  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2009
    Posts
    398

    Count got files while Directory.EnumerateFiles

    Directory.EnumerateFiles(Folder, mask, SearchOption.AllDirectories)

    can take several seconds if the search folder contains hundreds of subfolders and thousands of files.

    There is way to get the progressive file counting during the files enumeration?

  2. #2
    Hyperactive Member
    Join Date
    Sep 2017
    Posts
    418

    Re: Count got files while Directory.EnumerateFiles

    To achieve that you may need to recursively iterate the files and folders and add a counter.

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    98,635

    Re: Count got files while Directory.EnumerateFiles

    I think that you may be missing the point of EnumerateFiles. The whole point of that method is that it doesn't get all the file upfront, so you can start using the files immediately. Originally, the Directory class only had the GetFiles method. It would do the entire search first, and get the list of file paths, then you could loop through that list. The point of EnumerateFiles is that you use the file paths as they are found. You are supposed to use EnumerateFiles like this:
    vb.net Code:
    1. For Each filePath In Directory.EnumerateFiles(folderPath)
    If you're not doing that then you're doing it wrong and if you are doing that then you can simply count by incrementing a variable inside the loop.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width