跨平台的目录遍历实现方法(windows和linux已经测试)

dirent.h是gcc下的一个头文件,在windows中是没有的。这个文件中封装了几个对目录进行操作函数:

static DIR *opendir (const char *dirname);
static struct dirent *readdir (DIR *dirp);
static int closedir (DIR *dirp);

对于在linux->windows之间进行程序移植来讲常常会造成一些困扰。

 

有一个开源的源码可以解决这个问题。 

源码可以从下面的链接下载得到,这个源码是跨平台的。

http://softagalleria.net/dirent.php

 

这里包含了一个头文件dirent.h,这个头文件就是实现。

其他的几个c文件是怎么样使用。我在vs2008和ubuntu下测试了find.c这个文件,目录遍历功能一切正常。

 

posted @ 2015-07-25 16:18  matthew2015  阅读(1062)  评论(0编辑  收藏  举报