Hi All,
I am trying to read all the files in a directory if there are any subdirectories i want to skip them. I wrote a small script but this reads sub directories also. Is there a way to skip subdirectories?
#include <stdio.h>
#include <dirent.h>
main(int argc, char **argv) {
DIR *D1;
struct dirent *dp;
short ret=0;
printf("input args %s",argv[1]);
while(!ret) {
if((D1=opendir(argv[1]))==NULL) {
printf("Failed to open files \n");
ret = 1;
} else {
while( (dp = readdir(D1)) != NULL) {
if (!strcmp(dp->d_name, ".")) continue;
printf("After first if condition \n");
if (!strcmp(dp->d_name, "..")) continue;
printf("After second if condition \n");
printf("FileName is [%s] \n",dp->d_name);
} /* while dp loop */
ret=1;
} /* else loop */
} /* while loop */
closedir(D1);
}
Thanks for your help!
I am trying to read all the files in a directory if there are any subdirectories i want to skip them. I wrote a small script but this reads sub directories also. Is there a way to skip subdirectories?
#include <stdio.h>
#include <dirent.h>
main(int argc, char **argv) {
DIR *D1;
struct dirent *dp;
short ret=0;
printf("input args %s",argv[1]);
while(!ret) {
if((D1=opendir(argv[1]))==NULL) {
printf("Failed to open files \n");
ret = 1;
} else {
while( (dp = readdir(D1)) != NULL) {
if (!strcmp(dp->d_name, ".")) continue;
printf("After first if condition \n");
if (!strcmp(dp->d_name, "..")) continue;
printf("After second if condition \n");
printf("FileName is [%s] \n",dp->d_name);
} /* while dp loop */
ret=1;
} /* else loop */
} /* while loop */
closedir(D1);
}
Thanks for your help!