Re: gtk_file_chooser_get_filenames multiple folders

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

 



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

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux