Xref: utzoo comp.lang.c:31030 comp.sys.sgi:5285 Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!zaphod.mps.ohio-state.edu!samsung!crackers!jjmhome!smds!rh From: rh@smds.UUCP (Richard Harter) Newsgroups: comp.lang.c,comp.sys.sgi Subject: Re: List a directory in a C program on Unix machines Summary: encapsulate the directory read Message-ID: <159@smds.UUCP> Date: 11 Aug 90 19:00:48 GMT References: <1990Aug10.154506.846@caen.engin.umich.edu> <1990Aug10.213953.25619@cubmol.bio.columbia.edu> Followup-To: comp.lang.c Distribution: usa Organization: SMDS Inc., Concord, MA Lines: 31 In article <1990Aug10.213953.25619@cubmol.bio.columbia.edu>, ping@cubmol.bio.columbia.edu (Shiping Zhang) writes: > In article <1990Aug10.154506.846@caen.engin.umich.edu> cys@caen.engin.umich.edu writes: > > I am currently writing a C program on Unix machines. What I want to > >do is to store the file names in a directory into a character array. > >So I can do something to those files. I want to use Unix system calls > >to handle it. Could anyone help me out with that? > I think opendir(), readdir() etc. can handle this problems. Check > your man pages. But be warned. There are some portability pitfalls so the routine to fetch the file names should be encapsulated. The major variants that I can think of offhand are: (a) BSD Uses (b) SYS V Uses (c) SYS V Older versions of SYS V may not have these routines. You can write your own. THe directory is a file containing an array of structures which can be read. The format is in the manual. (d) VMS Write your own. There are C callable VMS library routines for extracting the needed information. (e) Primos Has a routine called lsdir which returns just what you want. -- Richard Harter, Software Maintenance and Development Systems, Inc. Net address: jjmhome!smds!rh Phone: 508-369-7398 US Mail: SMDS Inc., PO Box 555, Concord MA 01742 This sentence no verb. This sentence short. This signature done.