get the file directory
Shiang Chin
cs00wsc at unccvax.UUCP
Wed Nov 15 18:35:07 AEST 1989
I am trying to the file list of a file directory on
Sun station running Unix. Can someone read the following
C code for me; I don't know what's wrong on my code.
#include <stdio.h>
#include <sys/types.h>
#include <sys/dir.h>
main(){
dir(".");
exit(0);
}
int dir(path)
char* path;
{
int fd;
struct direct nbuf;
if ((fd = open(path,0)) == -1)
return (0);
while (read(fd,&nbuf, DIRSIZ(&nbuf)) {
if (nbuf.d_fileno != 0)
printf("%u %s\n",nbuf.d_namlen,nbuf.d_name);
else
printf("error\n");
}
return 1;
}
------------------------------------------------------------------
If anyone knows the problem, please tell me how to solve this.
Thanks a lot.
More information about the Comp.lang.c
mailing list