#include #include #include #include #include #include #include "sys/stat.h" using namespace std; int main(void){ DIR *dir; struct dirent *ent; if ((dir = opendir (".")) != NULL) { /* print all the files and directories within directory */ while ((ent = readdir (dir)) != NULL) { //printf ("%s\n", ent->d_name); string katalooginimi=ent->d_name; string lopp=".txt"; //cout << katalooginimi << endl; if(katalooginimi.length()>4){ if(katalooginimi.compare(katalooginimi.length()-4, 4, lopp)==0){ //cout << " lopp " << katalooginimi << endl; std::ifstream ifs(katalooginimi.c_str()); std::string content( (std::istreambuf_iterator(ifs) ), (std::istreambuf_iterator() ) ); std::cout << content << endl; } } struct stat s; if(stat(ent->d_name, &s)==0){ if(s.st_mode & S_IFDIR){ cout << "kataloog " << ent->d_name << endl; DIR *dir2; struct dirent *ent2; if ((dir2 = opendir (ent->d_name)) != NULL) { while ((ent2 = readdir (dir2)) != NULL) { string katalooginimi2=ent2->d_name; cout << "seest leiti " << katalooginimi2 << endl; if(katalooginimi2.length()>4){ if(katalooginimi2.compare(katalooginimi2.length()-4, 4, lopp)==0){ cout << " lopp " << katalooginimi2 << endl; std::ifstream ifs2((katalooginimi+"/"+katalooginimi2).c_str()); std::string content2( (std::istreambuf_iterator(ifs2) ), (std::istreambuf_iterator() ) ); std::cout << content2 << endl; } } } closedir(dir2); } } } } closedir (dir); } else { /* could not open directory */ perror (""); return EXIT_FAILURE; } }