开发者

Getting number of files in a partition

I wrote a code in C++ CLI which can loop through all files in the system. I want to know the number of files are existing 开发者_运维知识库in the system programmatically without counting the files one by one! Also...Would that number be useful in scanning progress bar?


If you are using NTFS, you can call the FSCTL_GET_NTFS_VOLUME_DATA IoControl to get a whole bunch of data for your volume. The number of files will be at most MftValidDataLength / BytesPerFileRecordSegment. Keep in mind that this is a maximum number of files that can be on the volume, so the actual number will always be less.

I would also hope that you'd be using FSCTL_ENUM_USN_DATA to read the files rather than walking the directory tree (which is inaccurate and error-prone). This thread has an example of somebody doing it in C#: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/c1550294-d121-4511-ac32-31551497f64e/


That would depend highly on the filesystem in use (and the administrative privileges held by the impersonated user :))

You might find something here or you can enhance your question with more details

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜