Mam ten kod, który otwiera katalog i sprawdza, czy lista nie jest zwykłym plikiem (oznacza to, że jest to folder), czy też go otworzy. Jak rozróżnić pliki i foldery za pomocą C++. tu jest mój kodu, jeśli pomaga to:Rozróżnianie folderów i plików w 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;
}
użyć 'stat' (lub' lstat') i 'S_ISDIR'. –