Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* You will need to include the following headers on your C++ class declaration file the all works
- *
- *Info on this can be found at this address http://www.gnu.org/software/libc/manual/html_node/
- * Reading_002fClosing- Directory.html#Reading_002fClosing-Directory
- */
- #include <dirent.h>
- #include <sys/types.h>
- #include <cstring>
- void ReadFile::listFiles(const char* dirname)
- {
- DIR *di;
- char *ptr1,*ptr2;
- int retn;
- struct dirent *dir;
- di = opendir(dirname); //specify the directory name
- if (di)
- {
- while ((dir = readdir(di)) != NULL)
- {
- ptr1=strtok(dir->d_name,dirname);
- ptr2=strtok(NULL,".");
- if(ptr2!=NULL)
- {
- retn=strcmp(ptr2,"txt");
- if(retn==0)
- {
- printf("%s\t",ptr1);
- }
- }
- }
- closedir(di);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement