Re: directory listing



thanks a lot,
-sreenidhi,


Joergen Scheibengruber wrote:

Am Don, 2001-12-20 um 14.57 schrieb Sreenidhi.B.G:
Hi all,
is there a way to scan the current directory and get the filenames ,
runtime. I cannot afford to create and display widget, get the selection
and then use "gtk_get_selection_file_name", I'm looking for some way
(API) to get me the filenames in the current directory,
thanks

-sreenidhi

Hi! here is something i did once in a app, i think you can use it:

#include <dirent.h>
#include <sys/types.h>

/* you need to include this */

DIR *dir;
gchar *directory, *tmp;
GList *list;

/* variables */

if ((dir = opendir(directory)) == NULL)
                return NULL;

list = NULL;


while (( dir_info = readdir(dir)) != NULL)
{
        tmp = g_strjoin("/", directory, dir_info->d_name, NULL);
        list = g_list_append(list, (gpointer)tmp);
}
closedir(dir);

list = g_list_sort(list, (GCompareFunc)g_strcasecmp);

/* Thats it all files (with full path) from directory in a sorted GList
:-) */

Maybe there is a function in gnome-vfs that does something similiar, so
you should look there, too...

Greetings,
Jörgen

--
There are two major products that come from Berkeley : LSD and UNIX. We
don't believe this to be a coincidence.

Jeremy S. Anderson




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