static void readFiles()
{ Â// called on user selection from GtkFileChooser
ÂÂGSList Â*selected, *sel;
ÂÂsel = selected = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(fileSel));
ÂÂwhile(selected)
ÂÂ{
ÂÂ ÂgetFiles(selected->data);
ÂÂ Âg_free(selected->data);
ÂÂ Âselected=selected->next;
ÂÂ}
ÂÂg_slist_free(sel);
}
On Tue, Feb 8, 2011 at 11:06 AM, richard boaz <ivor.boaz@xxxxxxxxx> wrote:
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 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 ============2011/2/8 David NeÄas <yeti@xxxxxxxxxxxxxxx>
On Tue, Feb 08, 2011 at 02:35:02AM +0000, Kevin.S.Anthony@xxxxxxxxx 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@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list
_______________________________________________ gtk-list mailing list gtk-list@xxxxxxxxx http://mail.gnome.org/mailman/listinfo/gtk-list