eina_file_example_01_page

For brevity, variable declarations and initialization are 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 EINA_UNUSED)
{
printf("file %s in %s\n", name, path);
}
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339

We can use this callback in the following call:

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

The above is 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_API Eina_Iterator * eina_file_ls(const char *dir)
Gets an iterator to list the content of a directory.
Definition: eina_file_posix.c:631
EINA_API void eina_iterator_free(Eina_Iterator *iterator)
Frees an iterator.
Definition: eina_iterator.c:98
#define EINA_ITERATOR_FOREACH(itr, data)
Definition for the macro to iterate over all elements easily.
Definition: eina_iterator.h:448
EINA_API void eina_stringshare_del(Eina_Stringshare *str)
Notes that the given string has lost an instance.
Definition: eina_stringshare.c:533

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_API Eina_Iterator * eina_file_stat_ls(const char *dir)
Gets an iterator to list the content of a directory, with direct information.
Definition: eina_file_posix.c:739
it = eina_file_direct_ls("/home/");
printf("%s if of type %d\n", f_info->path, f_info->type);
EINA_API Eina_Iterator * eina_file_direct_ls(const char *dir)
Gets an iterator to list the content of a directory, with direct information.
Definition: eina_file_posix.c:679

The above mentioned ways of getting files on a list may produce the same output, but they have an important difference, eina_file_direct_ls() does 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().