使用“FindFirstFileA"查找目录中的所有文件;- C [英] Find all files within directory using "FindFirstFileA" - C

查看:42
本文介绍了使用“FindFirstFileA"查找目录中的所有文件;- C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Windows API,并希望能够搜索指定的目录并返回驻留在其中的任何文件的名称.

I am using the Windows API and would like to be able to search through a specified directory and return the names of any files that reside within it.

我已经开始了,但是我遇到了砖墙,因为我不确定如何更进一步.

I've made a start at it however i've hit a brick wall as i'm unsure of how to go any further.

这是我目前的进展:

#include <stdio.h>
#include <windows.h>

void main()
{
 HANDLE fileHandle;
 WIN32_FIND_DATAA fileData;

 fileHandle = FindFirstFileA("*.txt", &fileData);

 if(fileHandle != INVALID_HANDLE_VALUE)
 {
  printf("%s \n", fileData.cFileName);
 }
}

推荐答案

您需要循环调用 FindNextFile 来查找所有文件.有一个完整的例子这里,这里是有趣的部分:

You need to call FindNextFile in a loop to find all the files. There's a full example here, here are the interesting bits:

hFind = FindFirstFile(szDir, &ffd);

if (INVALID_HANDLE_VALUE == hFind) 
   return dwError;

do
{
   printf("%s\n"), ffd.cFileName);
}
while (FindNextFile(hFind, &ffd) != 0);

这篇关于使用“FindFirstFileA"查找目录中的所有文件;- C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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