| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 1.91

 

load_dir_list

#include "sfldir.h"
NODE *
load_dir_list (
    const char *dir_name,
    const char *sort)

Synopsis

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.
If the sort string is NULL, no sort is carried out.

Source Code - (sfldir.c)

{
    NODE
        *file_list;                     /*  File list head                   */
    FILEINFO
        *file_info;
    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)
      {
        file_info = (FILEINFO *) node create (file_list-> prev,
                                              sizeof (FILEINFO));
        if (file_info)                  /*  If node allocated okay           */
          {
             memcpy  (&file_info-> dir, &dir, sizeof (DIRST));
             fix dir (&file_info-> dir);
             file_info-> directory = (dir.file_attrs & ATTR_SUBDIR) != 0;
             nbr_files++;
          }
        rc = read dir (&dir);
      }
    close dir (&dir);

    if (nbr_files > 1 && sort != NULL)
        sort_dir (file_list, sort);

    return (file_list);
}

| << | < | > | >> iMatix Copyright © 1996-98 iMatix