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



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