Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!wuarchive!cs.utexas.edu!usc!sdsu!ctrsol!uakari.primate.wisc.edu!aplcen!haven!uvaarpa!mcnc!unccvax!cs00wsc From: cs00wsc@unccvax.UUCP (Shiang Chin) Newsgroups: comp.lang.c Subject: get the file directory Keywords: directory Message-ID: <1724@unccvax.UUCP> Date: 15 Nov 89 07:35:07 GMT Distribution: usa Organization: Univ. of NC at Charlotte, Charlotte, NC Lines: 32 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 #include #include 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.