Counting Files and Folders

Abhay Kumar

New Member
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 Computer

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 Computer

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 Computer

Back
Top