Ho questo codice che apre una directory e controlla se l'elenco non è un file normale (significa che è una cartella) lo aprirà anche. Come posso distinguere tra file e cartelle con C++. Ecco il mio codice se questo aiuta:Distinguere tra cartelle e file in C++
#include <sys/stat.h>
#include <cstdlib>
#include <iostream>
#include <dirent.h>
using namespace std;
int main(int argc, char** argv) {
// Pointer to a directory
DIR *pdir = NULL;
pdir = opendir(".");
struct dirent *pent = NULL;
if(pdir == NULL){
cout<<" pdir wasn't initialized properly!";
exit(8);
}
while (pent = readdir(pdir)){ // While there is still something to read
if(pent == NULL){
cout<<" pdir wasn't initialized properly!";
exit(8);
}
cout<< pent->d_name << endl;
}
return 0;
}
Usa 'stat' (o' lstat') e 'S_ISDIR'. –