Windows Vista Forums

Counting Files and Folders
  1. #1



    Newbie
    Join Date : Mar 2009
    Posts : 1
    Vista Ultimate x64
    Local Time: 01:55 PM

    Counting Files and Folders

    Hi,

    When we right click on any folder or drive, and then see Properties, Windows shows count of files and folders. My question is that what technique Windows uses to count files and folders? Does it uses FindFirstFile() and FindNextFile() API or some other techniques? My doubt is because my program shows count slower than Windows. Anyone please clear my doubt.

    Thanks and Regards,
    Abhay


      My System SpecsSystem Spec

  2. #2
    SuperFuzz's Avatar

    The Patriot
    Join Date : Apr 2007
    Posts : 76
    Vista Ultimate x64 SP1
    Local Time: 02:25 AM
    usa us idaho

     

    Re: Counting Files and Folders

    Quote Originally Posted by Abhay Kumar View Post
    Hi,

    When we right click on any folder or drive, and then see Properties, Windows shows count of files and folders. My question is that what technique Windows uses to count files and folders? Does it uses FindFirstFile() and FindNextFile() API or some other techniques? My doubt is because my program shows count slower than Windows. Anyone please clear my doubt.

    Thanks and Regards,
    Abhay
    Sardinian Guy posted a prior topic on this and found out how to count files using powershell. Here is a link to that topic so you can check and see if his information answers your question. Good luck!

      My System SpecsSystem Spec

  3. #3
    H2SO4's Avatar

    A bit of a numpty
    Join Date : Mar 2009
    Australia
    Posts : 1,241
    Win7x64
    Local Time: 02:25 AM
    australia

     

    Re: Counting Files and Folders

    Interesting question.

    If you rightclick and bring up the properties of a drive, that uber-quick pie chart works by querying NTFS metadata structures which always maintain a "free space" counter. There's no count of files or folders in that case, only used and free space.

    However, it looks like kernel32!FindFirstFile is indeed used when you interrogate a specific folder, or at least that breakpoint is hit as soon as I click folder "properties" while the machine is under a debugger:

    kd> kL
    ChildEBP RetAddr
    00e8ed40 7cb12454 kernel32!FindFirstFileW
    00e8ed5c 7cb13d59 SHELL32!HIDA_FillFindData+0x3b
    00e8f1a0 7cb158c3 SHELL32!InitCommonPrsht+0x76
    00e8fb70 7cac2ef5 SHELL32!FileSystem_AddPages+0x6e
    00e8fb84 7ca7917a SHELL32!CShellExecMenu::AddPages+0x14
    00e8fbac 7ca795b2 SHELL32!DCA_AppendClassSheetInfo+0x78
    00e8fcc8 7cad5dd2 SHELL32!SHOpenPropSheetW+0x131
    00e8ff3c 7ca9071c SHELL32!CFSFolder::_PropertiesThread+0xba
    00e8ff50 77f76f42 SHELL32!_PropSheetThreadProc+0x18
    00e8ffb4 7c80b683 SHLWAPI!WrapperThreadProc+0x94
    00e8ffec 00000000 kernel32!BaseThreadStart+0x37

    kd> bl
    0 e 7c8137d9 0001 (0001) kernel32!FindFirstFileA
    1 e 7c80eee1 0001 (0001) kernel32!FindFirstFileW

    kd> !process -1 0
    PROCESS 864ab4e0 SessionId: 0 Cid: 0568 Peb: 7ffde000 ParentCid: 0534
    DirBase: 0e90d000 ObjectTable: e17822b0 HandleCount: 401.
    Image: explorer.exe

    If your code is substantially slower, maybe it's just a matter of optimisation. Are you doing this in native code or .Net? Can you post a snippet around your FindFirst/FindNext loop? (or link from pastebin.com)

      My System SpecsSystem Spec

Counting Files and Folders problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
vista leaves behind folders when moving folders with files in them power 3 Vista General 1 14 Nov 2008
Re: 1 3/4 hour and counting cvp Vista General 0 20 Oct 2007
How to count the total files under c:\abc\<* folders>\out where <* folders> are many folders? ABC PowerShell 2 15 Apr 2007
Counting files in a directory Jim PowerShell 2 04 Apr 2007
RC-1 install - 6 hrs and counting =?Utf-8?B?YmIzMzMz?= Vista installation & setup 1 08 Sep 2006