all filenames in directory in array/list
John Yuson Geer
geer-john at CS.YALE.EDU
Wed Feb 7 13:33:26 AEST 1990
In article <5302 at star.cs.vu.nl> mstuurm at cs.vu.nl (Mark Stuurman) writes:
>Could someone tell me how read all filenames in a directory into
>an array or a list (of filenames of course).
>
"scandir" is what you seek. It even allocates the array
of directory structures!
#include<stdio.h>
#include <sys/types.h>
#include <sys/dir.h>
main()
{
int num,i;
struct direct **namelist;
char dir[] = "/usr/bin/X11";
num = scandir(dir,&namelist,NULL,NULL);
for(i=0;i<num;i++)
fprintf(stderr,"%s\n",namelist[i]->d_name);
}
> Many thanks in advance,
> Mark Stuurman (mstuurm at cs.vu.nl)
>
>P.S. We use SunOS 4.0
no prob!
jyg'
---
geer at CS.YALE.EDU "This was because he was no mere dreamer but one
readnews be news one of those dreamer-doers, a guy with a program."
-_Henderson_the_Rain_King_ by Saul Bellow
Hochspannung Lebensgefahr
More information about the Comp.lang.c
mailing list