06-03-2008
Check out scandir(3) and alphasort().
9 More Discussions You Might Find Interesting
1. Filesystems, Disks and Memory
I am trying to read the directory contents throgh the readdir system call.
After getting the directory entry I am testing the type of it by using the folllowing macros S_ISDIR() S_ISREG() etc. But in some systems every file in the directory is displaying like a sub directory. and in some systems... (2 Replies)
Discussion started by: gandhevinod
2 Replies
2. UNIX for Dummies Questions & Answers
I read the description of the command readdir by using 'man readdir'. However, in the description i was suggesed to refer to readdir(3).
I wonder how to see the manual of readdir(3)
Thanks (1 Reply)
Discussion started by: cy163
1 Replies
3. Programming
I am having a hard time doing this and can't seem to find an example to help me. This is my code:
DIR *dirp=opendir(pathname);
struct stat filebuf;
struct dirent entry;
struct dirent *dp=&entry;
RWCString pattern;
for (int i = 0; i < request_->getNumStreams(); i++)
{
... (2 Replies)
Discussion started by: ajgwin
2 Replies
4. Shell Programming and Scripting
I am trying to script and came up with a conclusion that I need a do while loop in my statement. I am stuck with the
do while syntax. I need to use it alongwith the if then else statement. Can I use it is a big question? I actually need to get all the files
that are there from within run_dt to... (1 Reply)
Discussion started by: aronmelon
1 Replies
5. Shell Programming and Scripting
Quick question.
I can not get the context corrert on this code.
opendir(DIR, ".");
@fileldiv = grep(/l*/,readdir(DIR));
closedir(DIR);
I am trying to search all html files within a dir that start with l.
Thanks for your help. (1 Reply)
Discussion started by: mrlayance
1 Replies
6. SuSE
Dear Experts,
i am trying to find whether the given name is file or a directory
dirp = opendir(dirname);
direntp = readdir(dirp);
if(direntp->d_type & DT_DIR)
{
printf("\n is a dirctory");
}
else
{
//dir_or_file = Mtrue;
printf("\n not a directory");
}
it always... (9 Replies)
Discussion started by: vin_pll
9 Replies
7. Programming
Hi everyone
I am developing an utility.
At some part of it I read directory entries to a dynamic array: struct list
It stores pointers to items: list.entries,
which are structures: struct entry
If a number of files in a directory is greater then number of elements an array was initially... (11 Replies)
Discussion started by: torbium
11 Replies
8. Shell Programming and Scripting
Hi all,
I have little working knowledge in unix shell scripting. I have a requirement where i need to pull out some data in between the strings in the file.
Input:
TEST
a
a
c
f
d
TEST
f
e
g
g
TEST
Output: (7 Replies)
Discussion started by: satyasrin82
7 Replies
9. Shell Programming and Scripting
Hi All,
I have a source file with data
Name ~ Groups
Muni~abc,was,USA_ax,123
Chaitanya~USA_12,was
Balaji~123,xyz,was
Ramu~123,xyz
From the second column i want to extract only the groups that matches the pattern 'USA_%' or if the group = 'was', and ignore any other columns.
... (8 Replies)
Discussion started by: morbid_angel
8 Replies
LEARN ABOUT SUNOS
scandir
scandir(3C) Standard C Library Functions scandir(3C)
NAME
scandir, alphasort - scan a directory
SYNOPSIS
#include <sys/types.h>
#include <dirent.h>
int scandir(const char *dirname, struct dirent *(*namelist[]), int (*select)(const struct dirent *), int (*dcomp)(const struct dirent **,
const struct dirent **));
int alphasort(const struct dirent **d1, const struct dirent **d2);
DESCRIPTION
The scandir() function reads the directory dirname using readdir(3C) and builds an array of pointers to directory entries using malloc(3C).
The namelist argument is a pointer to an array of structure pointers. The select argument is a pointer to a routine that is called with a
pointer to a directory entry and returns a non-zero value if the directory entry is included in the array. If this pointer is NULL, then
all the directory entries are included. The dcomp argument is a pointer to a routine that is passed to qsort(3C), which sorts the completed
array. If this pointer is NULL, the array is not sorted.
The alphasort() function can be used as the dcomp() function parameter for the scandir() function to sort the directory entries into alpha-
betical order, as if by the strcoll(3C) function. Its arguments are the two directory entries to compare.
RETURN VALUES
The scandir() function returns the number of entries in the array and a pointer to the array through the namelist argument. When an error
is encountered, scandir() returns -1 and errno is set to indicate the error.
The alphasort() function returns an integer greater than, equal to, or less than 0 if the directory entry name pointed to by d1 is greater
than, equal to, or less than the directory entry name pointed to by d2 when both are interpreted as appropriate to the current locale.
There is no return value reserved to indicate an error.
ERRORS
The scandir() function will fail if:
EOVERFLOW The number of directory entries exceeds the number that can be represented by an int.
USAGE
The scandir() and alphasort() functions have transitional interfaces for 64-bit file offsets. See lf64(5).
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Stable |
+-----------------------------+-----------------------------+
|MT-Level |See below. |
+-----------------------------+-----------------------------+
The scandir() function is Unsafe. The alphasort() function is Safe.
SEE ALSO
malloc(3C), qsort(3C), readdir(3C), strcoll(3C), attributes(5), lf64(5)
SunOS 5.10 4 May 2004 scandir(3C)