#include <stdio.h>
#include <direct.h>
#include <io.h>
void demo()
{
intptr_t handle = NULL;
intptr_t handle_next = NULL;
struct _finddata_t cfile = {0};
_chdir("D:\\test\\"); // 改变当前目录;即:进入指定目录
handle = _findfirst("*.mp3", &cfile); // 在当前目录下查找文件或子目录;[支持通配符]
handle_next = handle;
while (handle_next != -1)
{
printf("[%s],[%dbyte]\n", cfile.name, cfile.size);
handle_next = _findnext(handle, &cfile); // 继续查找下一个
}
_findclose(handle);
}
int main(void)
{
demo();
getchar();
return 0;
}
_chdir、_findfirst、_findnext、_findclose函数的使用(枚举文件)
最新推荐文章于 2024-07-23 21:40:26 发布
本文提供了一个使用C语言编写的示例程序,该程序通过调用_findfirst和_findnext函数来搜索指定目录(如D:\test\)下的所有.mp3文件,并打印出每个文件的名称及其大小。
299

被折叠的 条评论
为什么被折叠?



