Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!batcomputer!cornell!rochester!rocksanne!stein From: stein@WRC.XEROX.COM (Adam Stein) Newsgroups: comp.unix.programmer Subject: Need a little example of scandir() Message-ID: <822@rocksanne.WRC.XEROX.COM> Date: 21 May 91 19:28:46 GMT Sender: news@WRC.XEROX.COM Reply-To: stein@WRC.XEROX.COM (Adam Stein) Distribution: world Organization: Imaging Science Engineering & Technology, Xerox Corporation Lines: 35 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@xerox.com -----Example----------Example----------Example----------Example--------- #include #include 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@xerox.com stein@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.