有比C ++ FindFirstFile / FindNextFile枚举文件夹更快的替代方法吗? [英] Is there a faster alternative to enumerating folders than FindFirstFile/FindNextFile with C++?

查看:349
本文介绍了有比C ++ FindFirstFile / FindNextFile枚举文件夹更快的替代方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取文件夹中的子文件夹的所有路径(使用WinAPI和C ++)。到目前为止,我找到的唯一解决方案是递归调用 FindFirstFile / FindNextFile ,但是在具有更深层次的文件夹上执行此操作需要大量的时间。所以我想知道,只是为了得到文件夹的名称,有一个更快的方法吗?

解决方案 div>

更快的方法是绕过 FindFirstFile ...() API直接进入文件系统。您可以使用 DeviceIoControl() FSCTL_ENUM_USN_DATA 控制访问主文件表,至少在NTFS格式的卷上。有了这些信息,您可以直接访问文件/文件夹的记录,其中包括它们的属性,父级信息等。是的,这将是更多的工作,但它也应该更快,因为您可以优化代码来访问你需要。

I need to get all paths to subfolders within a folder (with WinAPIs and C++.) So far the only solution that I found is recursively calling FindFirstFile / FindNextFile but it takes a significant amount of time to do this on a folder with a deeper hierarchy.

So I was wondering, just to get folder names, is there a faster approach?

解决方案

A faster approach would be to bypass the FindFirstFile...() API and go straight to the file system directly. You can use DeviceIoControl() with the FSCTL_ENUM_USN_DATA control to access the master file table, at least on NTFS formatted volumes. With that information, you can directly access the records for files/folders, which includes their attributes, parent info, etc. Yes, it would be more work, but it should also be faster since you can optimize the code to access just the pieces you need.

这篇关于有比C ++ FindFirstFile / FindNextFile枚举文件夹更快的替代方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆