2009-05-30 18:58:34 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <fat.h>
|
|
|
|
#include <sys/dir.h>
|
2009-06-05 00:13:39 +02:00
|
|
|
#include <dirent.h>
|
2009-05-30 18:58:34 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "listfiles.h"
|
|
|
|
|
|
|
|
|
2009-06-06 19:26:52 +02:00
|
|
|
static char alldirfiles[300][70];
|
|
|
|
char filenames[80];
|
2009-05-30 18:58:34 +02:00
|
|
|
|
2009-06-05 00:13:39 +02:00
|
|
|
bool findfile(const char * filename, const char * path)
|
|
|
|
{
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *file;
|
|
|
|
|
|
|
|
dir = opendir(path);
|
|
|
|
|
|
|
|
char temp[11];
|
|
|
|
while ((file = readdir(dir)))
|
|
|
|
{
|
|
|
|
snprintf(temp,sizeof(temp),"%s",file->d_name);
|
|
|
|
if (!strncmpi(temp,filename,11))
|
|
|
|
{
|
|
|
|
//WindowPrompt(path, filename,"go" ,0);
|
|
|
|
closedir(dir);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-06-06 19:26:52 +02:00
|
|
|
char * GetFileName(int i)
|
|
|
|
{
|
|
|
|
return alldirfiles[i];
|
|
|
|
}
|
2009-05-30 18:58:34 +02:00
|
|
|
|
|
|
|
s32 filenamescmp(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
/* Compare strings */
|
|
|
|
return stricmp((char *)a, (char *)b);
|
|
|
|
}
|
|
|
|
|
2009-06-06 19:26:52 +02:00
|
|
|
int GetAllDirFiles(char * filespath)
|
2009-05-30 18:58:34 +02:00
|
|
|
{
|
2009-06-10 01:26:03 +02:00
|
|
|
int countfiles = 0;
|
|
|
|
|
|
|
|
struct stat st;
|
|
|
|
DIR_ITER* dir;
|
|
|
|
dir = diropen (filespath);
|
|
|
|
|
|
|
|
if (dir == NULL) //If empty
|
2009-05-30 18:58:34 +02:00
|
|
|
return 0;
|
2009-06-06 19:26:52 +02:00
|
|
|
while (dirnext(dir,filenames,&st) == 0)
|
2009-06-10 01:26:03 +02:00
|
|
|
{
|
2009-05-30 18:58:34 +02:00
|
|
|
if ((st.st_mode & S_IFDIR) == 0)
|
2009-06-10 01:26:03 +02:00
|
|
|
{
|
2009-05-30 18:58:34 +02:00
|
|
|
// st.st_mode & S_IFDIR indicates a directory
|
2009-06-06 19:26:52 +02:00
|
|
|
snprintf(alldirfiles[countfiles], 70, "%s", filenames);
|
2009-05-30 18:58:34 +02:00
|
|
|
countfiles++;
|
|
|
|
}
|
|
|
|
}
|
2009-06-10 01:26:03 +02:00
|
|
|
dirclose(dir);
|
2009-05-30 18:58:34 +02:00
|
|
|
qsort(alldirfiles, countfiles, sizeof(char[70]), filenamescmp);
|
2009-06-10 01:26:03 +02:00
|
|
|
return countfiles;
|
2009-05-30 18:58:34 +02:00
|
|
|
}
|