#ifndef SEARCH_NODE_H
#define SEARCH_NODE_H
struct search_node
{
char filename[64];
struct search_node *next;
};
typedef struct search_node SEARCH_NODE;
#endif
int search_files(const unsigned char *dirname,SEARCH_NODE *head,unsigned int *jpg_number)
{
DIR *dir_ptr;
char *ptr1,*ptr2;
struct dirent *direntp;
unsigned int jpg_nums=0;
int i = 0,j=0;
SEARCH_NODE *p,*q;
if(dirname == NULL)
{
printf("dir name error/n");
return -1;
}
if ((dir_ptr = opendir(dirname)) == NULL)
{
printf("Cannot open dir/n");
return -1;
}
while((direntp = readdir(dir_ptr)) != NULL)
{
i = 0;
ptr1 = strstr(direntp->d_name, ".jpg");
ptr2 = strstr(direntp->d_name, ".jpeg");
if (ptr1||ptr2)
{
if(jpg_nums != 0)
{
p = (SEARCH_NODE *)malloc(sizeof(SEARCH_NODE));
//printf("find %d jpg file name(%d) : %s/n",jpg_nums,direntp->d_reclen,direntp->d_name);
while(direntp->d_name[i] != '/0')
{
p->filename[i] = direntp->d_name[i];
i++;
}
p->filename[i] = '/0';
}
if(jpg_nums == 0)
{
strcpy(head->filename,direntp->d_name
);
q = head;
}
else
{
q->next = p;
q = q->next;
}
jpg_nums++;
}
}
closedir(dir_ptr);
*jpg_number = jpg_nums;
return 0;
}