无法打开包含文件dirent.h [英] can not open include file dirent.h
本文介绍了无法打开包含文件dirent.h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我遇到错误无法打开包含文件dirent.h.没有
这样的文件或目录.代码在下面给出
我正在尝试使用目录扫描代码单个目录中有多个文件,我想一步一步地扫描它们
Hi All
I am getting error can not open include file dirent.h .No
such file or directory . the code is given below
I am trying to use directory scanning code A single directory have multiple files i want to scan them all step by step
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <vector>
#include <string>
#include <iostream>
#include <sys/stat.h> /* for stat() */
using namespace std;
int isDir(string path)
;
/*function... might want it in some class?*/
int getdir (string dir, vector<string> &dirlist, vector<string> &fileList)
{
DIR *dp;
struct dirent *dirp, *dirFp ;
if((dp = opendir(dir.c_str())) == NULL) {
cout << "Error(" << errno << ") opening " << dir << endl;
return errno;
}
while ((dirp = readdir(dp)) != NULL) {
if (strcmp (dirp->d_name, ".") != 0 && strcmp(dirp->d_name, "..") != 0) {
//dirlist.push_back(string(dirp->d_name));
string Tmp = dir.c_str()+ string("/") + string(dirp->d_name);
if(isDir(Tmp)) {
//if(isDir(string(dir.c_str() + dirp->d_name))) {
dirlist.push_back(Tmp);
getdir(Tmp,dirlist,fileList);
} else {
// cout << "Files :"<<dirp->d_name << endl;
fileList.push_back(string(Tmp));
}
}
}
closedir(dp);
return 0;
}
int isDir(string path)
{
struct stat stat_buf;
stat( path.c_str(), &stat_buf);
int is_dir = S_ISDIR( stat_buf.st_mode);
// cout <<"isDir :Path "<<path.c_str()<<endl;
return ( is_dir ? 1: 0);
}
int main()
{
string dir = string("/test1/mfs");
vector<string> dirlist = vector<string>();
vector<string> fileList = vector<string>();
getdir(dir,dirlist,fileList);
#if 0
for (unsigned int i = 0;i < dirlist.size();i++) {
cout << "Dir LIst" <<dirlist[i] << endl;
//string dirF = dir + "/" + dirlist[i];
//getdir(dirF,fileList);
}
#endif
for (unsigned int i = 0; i < fileList.size(); i++)
cout << "Files :"<<fileList[i]<< endl;
return 0;
}
请帮助解决此代码的问题简单的头文件错误无法理解为什么会发生
plz help whats problem with this code simple header file error is not understand able why this happen
推荐答案
这是因为dirent.h并不随VC6一起提供. br/>
只有以下编译器知道dirent.h
Turbo C ++(DOS)
GCC(跨平台)
MinGW(Microsoft Windows)
Borland C ++ Builder(Microsoft Windows)
您可以下载dirent.h并在VC6中使用,以下链接可能会对您有所帮助
http://www.softagalleria.net/dirent.php [
This is because dirent.h doesn''t come with VC6.
Only following compiler knows dirent.h
Turbo C++ (DOS)
GCC (Cross-platform)
MinGW (Microsoft Windows)
Borland C++ Builder (Microsoft Windows)
You can download dirent.h to use in VC6, following is the link which may help you
http://www.softagalleria.net/dirent.php[^]
这篇关于无法打开包含文件dirent.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文