File listing for current directory under Unix?

Geoff Clare gwc at root.co.uk
Fri May 10 23:52:31 AEST 1991


marekp at pnet91.cts.com (Marek Pawlowski) writes:

>Does anyone know of a way to get the filenames of the files in the current
>directory, in to a two dimensional array of sorts?

gordon at osiris.cso.uiuc.edu (John Gordon) writes:

>	Yes.  do a:    popen("ls *", "r");

That won't do what was asked for if there are any subdirectories under the
current directory.  To do it with popen() you should use either

	popen("/bin/ls", "r");
or
	popen("/bin/ls -a", "r");

depending on whether you want to include files beginning with "." or not.

As other people have already pointed out, it is much better to use
opendir(), readdir() and closedir() if you have them.
-- 
Geoff Clare <gwc at root.co.uk>  (Dumb American mailers: ...!uunet!root.co.uk!gwc)
UniSoft Limited, London, England.   Tel: +44 71 729 3773   Fax: +44 71 729 3273



More information about the Comp.lang.c mailing list