NA01
06-04-2006, 18:09
voglio una lista di tutti i file che ho dentro una dir, escludendo le directory e altre cose strane.
ho scritto questo codice:
vector<string>& FileUtils::listFile(string dirName){
vector<string>* fileList = new vector<string>;
string fileName;
DIR * dir;
struct stat data;
struct dirent * direntry ;
if((dir = opendir(dirName.c_str())) == NULL){
throw FileException();
}
fchdir(dirfd(dir));
while ((direntry = readdir (dir)) != NULL ){
stat(direntry->d_name, &data);
if(dirent->d_type == DT_REG){
fileName = direntry->d_name;
fileList->push_back(fileName);
}
}
closedir(dir);
return *fileList;
}
ma la condizione if(dirent->d_type == DT_REG){ non passa mai, sebbene esistano un pacco di file regolari...
che sbaglio?
grazie, ciao!
ho scritto questo codice:
vector<string>& FileUtils::listFile(string dirName){
vector<string>* fileList = new vector<string>;
string fileName;
DIR * dir;
struct stat data;
struct dirent * direntry ;
if((dir = opendir(dirName.c_str())) == NULL){
throw FileException();
}
fchdir(dirfd(dir));
while ((direntry = readdir (dir)) != NULL ){
stat(direntry->d_name, &data);
if(dirent->d_type == DT_REG){
fileName = direntry->d_name;
fileList->push_back(fileName);
}
}
closedir(dir);
return *fileList;
}
ma la condizione if(dirent->d_type == DT_REG){ non passa mai, sebbene esistano un pacco di file regolari...
che sbaglio?
grazie, ciao!