使用完整代码进行编辑:
int filename_extract(){
DIR *pDIR;
struct dirent *entry;
string file;
try{
if((pDIR=opendir("/home/xxx/Documents/enron_mail_20110402/maildir/allen-p/all_documents")) != NULL){
while((entry = readdir(pDIR))!=NULL){
if( strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0 ){
file = entry->d_name;
cout << file << " "; // Doesn't print anything
}
}
closedir(pDIR);
}
}catch(exception &e){
cout << "Error occured in filename_extract function " << e.what() << endl;
}
return 0;
}
但是entry-&gt; d_name不存储目录中的任何文件名,而/home/xxx/Documents/enron_mail_20110402/maildir/allen-p/all_documents
文件夹包含纯文本文档类型的文件,即:
1.
2.
3.
4.
....
648.
为什么它不能正常工作以及我做错了什么?