Re: gtk_file_chooser_get_filenames multiple folders

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:


======= BEGIN SNIPPET ============
enum {

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;

  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
  {  // succeeded, it must be a directory
      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);  
      newDirFile = g_strdup_printf("%s/%s", dirFile, ep->d_name);  
        case FTDIR:
        case FTFILE:
        case FTDONOTPROC:  // file type we don't care about, ignore...

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 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...


gtk-list mailing list
gtk-list gnome org

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]