枚举目录中的文件(使用WIN32 API) [英] Enumerate Files in a directory (using WIN32 API)
本文介绍了枚举目录中的文件(使用WIN32 API)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨伙计。
我希望在Win32上找到一些有效的代码来构建文件列表,当我选择一个必需的目录时/
我想去通过所有子目录提取所有文件(我的意思是一个递归函数)
我想,有人面临这样的任务,可以为我提供解决方案。
Thnx提前。
解决方案
这可以通过Windows APIFindFirstFile
来完成(FindFirstFileEx
)/FindNextFile
/FindClose
。请参阅:
http ://msdn.microsoft.com/en-us/library/windows/desktop/aa364418%28v=vs.85%29.aspx [ ^ ]。
注意这些函数查找当前目录中的所有文件系统对象:两个文件和目录。注意结构_WIN32_FIND_DATA
的字段是dwFileAttributes
,字段的值是FILE_ATTRIBUTE_ ...
常量,其中一个属性是FILE_ATTRIBUTE_DIRECTORY
。您可以测试是否在每个找到的项目的字段dwFileAttributes
中设置了此位,如果这是一个目录,则递归查找其中的文件。
请参阅:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365740%28v=vs.85%29.aspx [ ^ ] ,
http:/ /msdn.microsoft.com/en-us/library/windows/desktop/gg258117%28v=vs.85%29.aspx [ ^ ]。
现在清楚了吗?
您可以自己轻松找到这些信息。
-SA
Hi folks.
I hope to find some efficient code on Win32 to build a file list,when I choose a required directory/
I'd like to go through the all subdirectories to extract all files ( I mean a recursive function)
I think, that someone has faced that kind of task and could offer me the solution.
Thnx in advance.解决方案This can be done with Windows APIFindFirstFile
(FindFirstFileEx
) /FindNextFile
/FindClose
. Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364418%28v=vs.85%29.aspx[^].
[EDIT: answering a follow-up question]
Pay attention that these functions find all file system objects in a current directory: both files and directories. Pay attention that the structure_WIN32_FIND_DATA
has the fielddwFileAttributes
, the values of the fields areFILE_ATTRIBUTE_…
constants, and one of the attributes isFILE_ATTRIBUTE_DIRECTORY
. You can test if this bit is set in the fielddwFileAttributes
for each found item, and, if this is a directory, recursively find files in it.
Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365740%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/gg258117%28v=vs.85%29.aspx[^].
Is it clear now?
You could easily find this information by yourself.
—SA
这篇关于枚举目录中的文件(使用WIN32 API)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文