|
| iMatix home page | << | < | > | >> |
SFLVersion 2.10 |
#include "sfldir.h"
NODE *
load_dir_list (
const char *dir_name,
const char *sort)
Loads and sorts the contents of a directory. Returns a NODE pointer to a linked list containing the directory entries. Each node is a FILEINFO structure (mapped onto a NODE structure for purposes of manipulating the linked list). You can ask for the directory list to be sorted in various ways; in this case subdirectory entries are always sorted first. To specify the sort order you pass a string consisting of one or more of these characters, which are then used in order:
| n | Sort by ascending name. |
| N | Sort by descending name. |
| x | Sort by ascending extension. |
| X | Sort by descending extension. |
| t | Sort by ascending time and date. |
| T | Sort by descending time and date. |
| s | Sort by ascending size. |
| S | Sort by descending size. |
{
NODE
*file_list; /* File list head */
DIRST
dir;
Bool
rc;
int
nbr_files = 0;
file_list = mem_alloc (sizeof (NODE));
if (!file_list)
return (NULL);
node_reset (file_list); /* Initialise file list */
/* Load directory */
rc = open dir (&dir, dir_name);
while (rc)
{
add dir list (file_list, &dir);
nbr_files++;
rc = read dir (&dir);
}
close dir (&dir);
if (sort && nbr_files > 1)
sort dir list (file_list, sort);
return (file_list);
}
| | << | < | > | >> |
|