[comp.unix.questions] My post didn't work?

zane@ddsw1.MCS.COM (Sameer Parekh) (08/14/90)

That last post was dissolved by my .signature, (Can I delete a just posted and 
saved post with rn?)
How do I use readdir and the functions to read the directories of a unix in C?









-- 
**************************************************************************
*                                                                        *
*                             Sameer Parekh                              *
*                       C Programmer in Training                         *

gwyn@smoke.BRL.MIL (Doug Gwyn) (08/15/90)

In article <1990Aug14.034654.12584@ddsw1.MCS.COM> zane@ddsw1.MCS.COM (Sameer Parekh) writes:
>How do I use readdir and the functions to read the directories of a unix in C?

That's like asking "How do I program in C?"

For what it's worth, here's the test program that I include with my
public-domain distribution of POSIX directory access routines; maybe
it will answer whatever your real question is.

/*
	testdir -- basic test for C library directory access routines

	last edit:	25-Apr-1987	D A Gwyn
*/

#include	<sys/types.h>
#include	<stdio.h>
#include	<dirent.h>

extern void	exit();
extern int	strcmp();

main( argc, argv )
	int			argc;
	register char		**argv;
	{
	register DIR		*dirp;
	register struct dirent	*dp;
	int			nerrs = 0;	/* total not found */

	if ( (dirp = opendir( "." )) == NULL )
		{
		(void)fprintf( stderr, "Cannot open \".\" directory\n" );
		exit( 1 );
		}

	while ( --argc > 0 )
		{
		++argv;

		while ( (dp = readdir( dirp )) != NULL )
			if ( strcmp( dp->d_name, *argv ) == 0 )
				{
				(void)printf( "\"%s\" found.\n", *argv );
				break;
				}

		if ( dp == NULL )
			{
			(void)printf( "\"%s\" not found.\n", *argv );
			++nerrs;
			}

		rewinddir( dirp );
		}

	(void)closedir( dirp );
	exit( nerrs );
	}