enum {
FTDIR,
FTFILE,
FTDONOTPROC
};
static int fileType(char *name)
{ // is the input a file or a directory?
// can't use extended field d_type from dirent.h, doesn't exist on SOLARIS
DIR *dp;
int ret = FTFILE;
if (!((dp=opendir(name))==NULL))
{ // succeeded, it's a directory
ret = FTDIR;
closedir(dp);
}
return ret;
}
static void getFiles(char *dirFile)
{ // recursive function:
// descend into every directory and
// 1) if it's a directory call us again, or
// 2) if it's a file, register for processing
DIR *dp;
struct dirent *ep;
char *newDirFile;
if ((dp=opendir(dirFile))==NULL)
{ // failed, it must be a file
registerFile(dirFile);
}
else
{ // succeeded, it must be a directory
while((ep=readdir(dp)))
{
if (!strcmp(ep->d_name,".") ||
!strcmp(ep->d_name, ".."))
continue; // don't read '.' and '..' directories
#ifdef WIN32
newDirFile = g_strdup_printf("%s\\%s", dirFile, ep->d_name);
#else
newDirFile = g_strdup_printf("%s/%s", dirFile, ep->d_name);
#endif
switch(fileType(newDirFile))
{
case FTDIR:
getFiles(newDirFile);
break;
case FTFILE:
registerFile(newDirFile);
break;
case FTDONOTPROC: // file type we don't care about, ignore...
break;
}
free(newDirFile);
}
closedir(dp);
}
}
static void readFiles()
{ // called on user selection from GtkFileChooser
GSList *selected, *sel;
sel = selected = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(fileSel));
}
======= END SNIPPET ============