Need a little example of scandir()
Adam Stein
stein at WRC.XEROX.COM
Wed May 22 05:28:46 AEST 1991
I have been trying to use scandir() with little success. I have included below
a piece of code trying to use scandir. The code calls scandir() to get
all the files in a directory and then goes to print out the name of each
file. The problem is that the namelist given to scandir() comes back empty.
I can't get to the filenames. I'm using scandir() because it's easier
for scandir() to put together a list of files and I plan on using
the select and compare functions that scandir() would call. If anybody knows
what I'm doing wrong or has a simple example that works, please let me know.
Thanx.
Adam Stein
stein.wbst129 at xerox.com
-----Example----------Example----------Example----------Example---------
#include <sys/types.h>
#include <sys/dir.h>
myroutine()
{
int numfiles,loop;
struct direct *namelist;
if((numfiles = scandir(".",&namelist,NULL,NULL)) == -1) {
perror("myprogram");
exit(1);
}
for(loop = 0;loop < numfiles;++loop)
printf("Name -> <%s>\n",namelist[loop].d_name);
}
--
Adam Stein @ Xerox Corporation Email: stein.wbst129 at xerox.com
stein at arisia.xerox.com
Disclaimer: Any/All views expressed ...!uunet!xerox.com!stein.wbst129
here have been proved to be my own. Hopefully one of the above will work.
More information about the Comp.unix.programmer
mailing list