0

用完整代码编辑:

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->d_name 不存储目录中的任何文件名,并且/home/xxx/Documents/enron_mail_20110402/maildir/allen-p/all_documents文件夹包含纯文本文档类型的文件,即:

1.
2.
3.
4.
....
648.

为什么它不能正常工作,我在哪里做错了?

4

0 回答 0