eina_file_example_01_page

For brevity includes, variable declarations and initialization was omitted from this page, however the full source code can be seen here.

Here we have a simple callback to print the name of a file and the path that contains it:

static void
_print_cb(const char *name, const char *path, void *data)
{
printf("file %s in %s\n", name, path);
}

We can use this callback in the following call:

eina_file_dir_list("/home/", EINA_FALSE, _print_cb, NULL);
Eina_Bool eina_file_dir_list(const char *dir, Eina_Bool recursive, Eina_File_Dir_List_Cb cb, void *data)
List all files on the directory calling the function for every file found.
Definition eina_file.c:720
#define EINA_FALSE
boolean value FALSE (numerical value 0)
Definition eina_types.h:293

The above was a way to print the files in a directory, but it is not the only one:

it = eina_file_ls("/home/");
{
printf("%s\n", f_name);
}
Eina_Iterator * eina_file_ls(const char *dir)
Get an iterator to list the content of a directory.
Definition eina_file.c:785
#define EINA_ITERATOR_FOREACH(itr, data)
Macro to iterate over all elements easily.
Definition eina_iterator.h:332
void eina_iterator_free(Eina_Iterator *iterator)
Free an iterator.
Definition eina_iterator.c:96
void eina_stringshare_del(Eina_Stringshare *str)
Note that the given string has lost an instance.
Definition eina_stringshare.c:577

And now two ways to get more information than just file names:

it = eina_file_stat_ls("/home/");
printf("%s if of type %d\n", f_info->path, f_info->type);
Eina_Iterator * eina_file_stat_ls(const char *dir)
Get an iterator to list the content of a directory, with direct information.
Definition eina_file.c:887
it = eina_file_direct_ls("/home/");
printf("%s if of type %d\n", f_info->path, f_info->type);
Eina_Iterator * eina_file_direct_ls(const char *dir)
Get an iterator to list the content of a directory, with direct information.
Definition eina_file.c:830

The above ways of getting files on a list may produce the same output, but they have an important difference, eina_file_direct_ls() will not call stat, this means that on some systems it might not have file type information. On the other hand it might be faster than eina_file_stat_ls().