GRASS Programmer's Manual
6.5.svn(2014)-r66266
|
Functions to list the files in a directory. More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <grass/gis.h>
#include <grass/config.h>
#include <grass/glocale.h>
Go to the source code of this file.
Typedefs | |
typedef int | ls_filter_func (const char *, void *) |
Functions | |
void | G_set_ls_filter (ls_filter_func *func, void *closure) |
Sets a function and its complementary data for G__ls filtering. More... | |
void | G_set_ls_exclude_filter (ls_filter_func *func, void *closure) |
char ** | G__ls (const char *dir, int *num_files) |
Stores a sorted directory listing in an array. More... | |
void | G_ls (const char *dir, FILE *stream) |
Prints a directory listing to a stream, in prettified column format. More... | |
void | G_ls_format (char **list, int num_items, int perline, FILE *stream) |
Prints a listing of items to a stream, in prettified column format. More... | |
Functions to list the files in a directory.
(C) 2007, 2008 by the GRASS Development Team
This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
Definition in file ls.c.
char** G__ls | ( | const char * | dir, |
int * | num_files | ||
) |
Stores a sorted directory listing in an array.
The filenames in the specified directory are stored in an array of strings, then sorted alphabetically. Each filename has space allocated using G_store(), which can be freed using G_free() if necessary. The same goes for the array itself.
dir | Directory to list |
num_files | Pointer to an integer in which the total number of files listed will be stored |
Definition at line 88 of file ls.c.
References G_fatal_error(), G_store(), n, NULL, opendir(), and readdir().
Referenced by G_ls(), and list_mapsets().
void G_ls | ( | const char * | dir, |
FILE * | stream | ||
) |
Prints a directory listing to a stream, in prettified column format.
A replacement for system("ls -C"). Lists the contents of the directory specified to the given stream, e.g. stderr. Tries to determine an appropriate column width to keep the number of lines used to a minimum and look pretty on the screen.
dir | Directory to list |
stream | Stream to print listing to |
Definition at line 129 of file ls.c.
References G__ls(), G_free(), G_ls_format(), and n.
Referenced by list_locations().
Prints a listing of items to a stream, in prettified column format.
Lists the contents of the array passed to the given stream, e.g. stderr. Prints the number of items specified by "perline" to each line, unless perline is given as 0 in which case the function tries to determine an appropriate column width to keep the number of lines used to a minimum and look pretty on the screen.
list | Array of strings containing items to be printed |
num_items | Number of items in the array |
perline | Number of items to print per line, 0 for autodetect |
stream | Stream to print listing to |
Definition at line 159 of file ls.c.
References max.
Referenced by G_ls().
void G_set_ls_exclude_filter | ( | ls_filter_func * | func, |
void * | closure | ||
) |
void G_set_ls_filter | ( | ls_filter_func * | func, |
void * | closure | ||
) |
Sets a function and its complementary data for G__ls filtering.
Defines a filter function and its rule data that allow G__ls to filter out unwanted file names. Call this function before G__ls.
func | Filter callback function to compare a file name and closure pattern (if NULL, no filter will be used). func(filename, closure) should return 1 on success, 0 on failure. |
closure | Data used to determine if a file name matches the rule. |