Tengo este código que abre un directorio y comprueba si la lista no es un archivo normal (significa que es una carpeta) sino que también se abrirá. ¿Cómo puedo distinguir entre archivos y carpetas con C++? aquí es mi código si esto ayuda:Distinga entre carpetas y archivos en 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;
}
Use 'stat' (o' lstat') y 'S_ISDIR'. –