For completeness, another way:
struct stat pent_stat; if (stat(pent->d_name, &pent_stat)) { perror(argv[0]); exit(8); } const char *type = "special"; if (pent_stat.st_mode & _S_IFREG) type = "regular"; if (pent_stat.st_mode & _S_IFDIR) type = "a directory"; cout << pent->d_name << " is " << type << endl;
You will need to correct the file name with the source directory if it is different from .
source share