c++遍历文件夹
来源:互联网 发布:阿里云 苏州代理商 编辑:程序博客网 时间:2024/06/03 14:48
#include <dirent.h>
int scandir( const char *dir,
struct dirent ***namelist,
int (*filter) (const void *b),
int ( * compare )( const struct dirent **, const struct dirent ** ) );
int alphasort(const void *a, const void *b);
int versionsort(const void *a, const void *b);
函数scandir扫描dir目录下(不包括子目录)满足filter过滤模式的文件,返回的结果是compare函数经过排序的,并保存在namelist中。注意namelist是通过malloc动态分配内存的,所以在使用时要注意释放内存。alphasort和versionsort是使用到的两种排序的函数。
当函数成功执行时返回找到匹配模式文件的个数,如果失败将返回-1。
eg:
#include <dirent.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
struct dirent **namelist;
int n;
n = scandir(".", &namelist, 0, alphasort);
if (n < 0)
{
perror("not found\n");
}
else
{
while(n--)
{
printf("%s\n", namelist[n]->d_name);
free(namelist[n]);
}
free(namelist);
}
}
0 0
- c遍历文件夹
- C/C++遍历文件夹
- c 遍历文件夹
- C/C++ 遍历文件夹
- C#--遍历文件夹实例
- C/C++遍历文件夹
- c/c++遍历文件夹
- C、 C++遍历文件夹,删除文件夹
- linux下C遍历文件夹
- C语言实现遍历文件夹
- C遍历文件夹下文件
- 如何c语言遍历文件夹
- Linux C 文件夹遍历接口.
- Linux C语言遍历文件夹
- C、C++文件夹文件遍历
- 文件夹遍历代码C++(win32平台)
- C/C++遍历文件夹(转)
- C Windows 读取文件夹 遍历文件
- 狗爹这名字取得好难听
- 在Spring中结合Dbunit对Dao进行集成单元测试
- java利用飞信接口发送短信
- 揭秘:4家企业新项目获得阿里云创投资金
- 深入理解JVM学习笔记——第十三章 线程安全与锁优化
- c++遍历文件夹
- sift描述子
- 排序之基数排序
- Oracle中REDO日志
- 体验指针函数
- 面向对象设计
- Android客户端与数据库交互数据的简单学习
- 2013总结随记
- android ImageView Left值获取不到的解决方案