i do this just fine. but you must do the recursive traversal yourself.a code snippet illustrating how is below. this is not stand-alone, i.e., it will not compile. you must add your own code to:
- set up and execute the file selector itself (here named fileSel),
- write the routine registerFile(), which is responsible for registering the file with your program for subsequent processing, whatever that means to you. (typically, a list that, once completely filled (i.e., as returned from file selector), is traversed for individual file processing; though there are certainly other ways to effectuate this.)
- as well, the routine fileType() can be expanded to explicitly include/allow for only certain file types, returning:
- FTDIR - it's a directory
- FTFILE - it's a file to process
- FTDONOTPROC - it's a file we don't care about, so ignore
cheers,richard======= BEGIN SNIPPET ============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 SOLARISDIR *dp;int ret = FTFILE;if (!((dp=opendir(name))==NULL)){ // succeeded, it's a directoryret = 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 processingDIR *dp;struct dirent *ep;char *newDirFile;if ((dp=opendir(dirFile))==NULL){ // failed, it must be a fileregisterFile(dirFile);}else{ // succeeded, it must be a directorywhile((ep=readdir(dp))){if (!strcmp(ep->d_name,".") ||!strcmp(ep->d_name, ".."))continue; // don't read '.' and '..' directories#ifdef WIN32newDirFile = g_strdup_printf("%s\\%s", dirFile, ep->d_name);#elsenewDirFile = g_strdup_printf("%s/%s", dirFile, ep->d_name);#endifswitch(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 GtkFileChooserGSList *selected, *sel;sel = selected = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(fileSel));}======= END SNIPPET ============2011/2/8 David Nečas <yeti physics muni cz>
On Tue, Feb 08, 2011 at 02:35:02AM +0000, Kevin S Anthony gmail com wrote:
> Is there a way, to use gtk_file_chooser_get_filenames to recursively
> descend into all the folders selected?
>
> so you select folders ABC
> and click open,
> you then go into ABC and select and return all the files in each subfolder,
No. You can use GFileEnumerator or GDir to traverse the tree – deciding
how to handle hidden files, symlinks to directories, crossing file
system boundaries, etc. as the definition of ‘all files’ depends...
Yeti
_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list