PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2015 Count got files while Directory.EnumerateFiles-VBForums
Results 1 to 3 of 3

Thread: Count got files while Directory.EnumerateFiles

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2009

    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
    Fanatic Member
    Join Date
    Sep 2017

    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
    Sydney, Australia

    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: 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.

Posting Permissions

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


Click Here to Expand Forum to Full Width