SCANDIR(3) Library Functions Manual SCANDIR(3)NAME
scandir, alphasort - scan a directory
SYNOPSIS
#include <sys/types.h>
#include <sys/dir.h>
scandir(dirname, namelist, select, compar)
char *dirname;
struct direct *(*namelist[]);
int (*select)();
int (*compar)();
alphasort(d1, d2)
struct direct **d1, **d2;
DESCRIPTION
Scandir reads the directory dirname and builds an array of pointers to directory entries using malloc(3). It returns the number of entries
in the array and a pointer to the array through namelist.
The select parameter is a pointer to a user supplied subroutine which is called by scandir to select which entries are to be included in
the array. The select routine is passed a pointer to a directory entry and should return a non-zero value if the directory entry is to be
included in the array. If select is null, then all the directory entries will be included.
The compar parameter is a pointer to a user supplied subroutine which is passed to qsort(3) to sort the completed array. If this pointer is
null, the array is not sorted. Alphasort is a routine which can be used for the compar parameter to sort the array alphabetically.
The memory allocated for the array can be deallocated with free (see malloc(3)) by freeing each pointer in the array and the array itself.
SEE ALSO directory(3), malloc(3), qsort(3), dir(5)DIAGNOSTICS
Returns -1 if the directory cannot be opened for reading or if malloc(3) cannot allocate enough memory to hold all the data structures.
4.2 Berkeley Distribution September 17, 1985 SCANDIR(3)
Check Out this Related Man Page
scandir(3) Library Functions Manual scandir(3)Name
scandir - scan a directory
Syntax
#include <sys/types.h>
#include <sys/dir.h>
scandir(dirname, namelist, select, compar)
char *dirname;
struct direct *(*namelist[]);
int (*select)();
int (*compar)();
alphasort(d1, d2)
struct direct **d1, **d2;
Description
The subroutine reads the directory dirname and builds an array of pointers to directory entries using It returns the number of entries in
the array and a pointer to the array through namelist.
The select parameter is a pointer to a user supplied subroutine which is called by to select which entries are to be included in the array.
The select routine is passed a pointer to a directory entry and should return a non-zero value if the directory entry is to be included in
the array. If select is null, then all the directory entries will be included.
The compar parameter is a pointer to a user supplied subroutine which is passed to to sort the completed array. If this pointer is null,
the array is not sorted. The is a routine which can be used for the compar parameter to sort the array alphabetically.
The memory allocated for the array can be deallocated with free by freeing each pointer in the array and the array itself. For further
information, see
Diagnostics
Returns -1 if the directory cannot be opened for reading or if cannot allocate enough memory to hold all the data structures.
See Alsodirectory(3), malloc(3), qsort(3), dir(5)scandir(3)
Hi,
Can anyone tell me how i can declare and allocate dynamically an array of pointers to structured type?? Is declaration something like this:?
struct_name ** array; (1 Reply)
Hi,
I have the following problem: i must allocate a dynamic array from a subroutine which should return such array to main function. The subroutine has already a return parameter so i thought of pass the array as I/O parameter. I tried the following program but it doesn't work (segmentation... (11 Replies)
I have written a function that fills an array and another function where if a parameter is supplied it will jump to that part of the array and cat it to the screen.
I need to put in some checks to make sure the parameter supplied is firstly a number and then not a number great than the length of... (2 Replies)
Hi all,
Can anyone provide help with getting the right syntax regarding array/pointers in C in the following code? Can't locate a specific example which clarifies this...
Say I declare a typedef to an array of pointers to some type...
/**
* An array of ptrs to sections
*/
typedef... (4 Replies)
Hi
I want to write a script which store all the parameters passed to the script into an array.
Once it is stored I want scan through the array and and delete those files for last month present inside the directory. The files in directory is appneded with YYYY_MM_DD.
I want to know how can I... (3 Replies)
What I am doing is creating a top menu, which a user will select a choice with a number entry. That number corresponds to a string in an array. I then want to assign that response to another array I've already declared.
For example:
#!/bin/bash
colors=(red blue yellow)
red=(cherry fire)... (2 Replies)
Doing some training code with arrays i run into the following issue: If i ask the user how long the array is supposed to be, malloc it and then ask for the values inside the array and return the list to main and assing it to a pointer to list of integers:
#include <stdio.h>
#include... (7 Replies)
I am struggling with the pointer to 2D-array (cf: 2D array of pointers). Can anybody help me elaborate how the pointer x moves in the memory to access the individual of y, especially the high lighted lines?
I have talked to one of the curators of the forum, but I am still not quite clear.
Here... (1 Reply)
Hi,
I need some help taking a selection from a command and adding part of the output to an array.
I'd like to read the items into the array, have the user chose an option from the array and put the item from column 1 into a variable.
The command is:
awless -l list routetables --columns... (7 Replies)