Hi,
I would make it even more simple, from the command prompt at the top of the directory you want to count the files run dir /a:-d /s
and the file count is display when it finishes.
Gary.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello All,
Is there an efficient way to get the file count for a filesystem which has lot of small files. Have used get-childitem cmdlet, however interested to know if there any alternate method to get the same fast.
Thanks!
Hi,
I would make it even more simple, from the command prompt at the top of the directory you want to count the files run dir /a:-d /s
and the file count is display when it finishes.
Gary.
Depending on your overall goal.... I like TreeSize Free. It's multithreaded.
https://www.jam-software.com/treesize_free
I use the GUI, but it appears capable of generating reports, if that's what you're looking for.
https://knowledgebase.jam-software.com/5859
The Pro version has more features.
Thanks everyone for the quick responses.
Basically I am looking for a mechanism which would take less time to get the filecount recursively. Will compare the results with both get-childitem and dir options.
Hello @Priya ,
Let's first consider how one can count files.
One way is to traverse the tree/network of files via recursive directory enumeration. Some features of file systems (such as hard links and reparse points) need to be considered and handled (e.g. recognizing hard links, (not) following reparse points).
All recursive directory enumeration implementations ultimately use the NtQueryInformationFile/ZwQueryInformationFile routine. One parameter of this routine is a FILE_INFORMATION_CLASS and there are several values that could be used (reporting different levels of information) - choosing the value that reports just enough information to count files (and detect hard links, reparse points, etc.) could save a small amount of time.
Another option is to enumerate the on-disk data structures that implement a file system. Assuming that "file system" means "volume", one could use FSCTL_GET_NTFS_* ioctls to enumerate the file records on an NTFS volume. A small amount of "well known but not officially documented" information might be needed to distinguish between plain files and directories.
Yet another option is to count the total number of files once and then use change tracking mechanisms to calculate the delta values for subsequent requests.
Gary