#include<unistd.h>
#include<dirent.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char** list(char* dir,int* len)
{
struct dirent** namelist;
char **ret=NULL,**sret=NULL;
int n,rindex,lindex; //index of ret and index of namelist
struct stat buf;
int slen=0; //store the number of files in the sub-directory
char path[1024];
int i;
n = scandir(dir, &namelist, 0, alphasort); //number of items in namelist
if (n < 0)
printf("scandir failed/n");
else
{
n-=2; //ignore dot and dot-dot
if(n<=0)
{
*len=0;
return ret;
}
rindex=n-1;
lindex=n+1;