tools/deprecated/grib_keys.c
/* Print a sorted list of files in the directory 'dir' whose extension is 'extn' */
Print a sorted list of files in the directory 'dir' whose extension is 'extn'
Print a sorted list of files in the directory ' dir ' whose extension is ' extn '
static void print_files_in_dir(const char* dir, const char* extension)
{
	int i, count = 0;
	struct dirent **files = NULL;
	count = scandir(dir, &files, 0, alphasort);
	if (count<0) {
		fprintf(stderr, "Could not read entries in the SAMPLES path. ");
		perror(dir);
		exit(1);
	}
	for (i=0; i<count; ++i) {
		if ( (strcmp(files[i]->d_name, ".") != 0) && (strcmp(files[i]->d_name, "..") != 0) ) {
			char buf[1024];
			char* extn = NULL; 
			sprintf(buf,"%s", files[i]->d_name);
			extn = strrchr(buf, '.');
			if (extn && strcmp(extn, extension) == 0) {
				*extn = '\0';  
				if (strlen(buf) > 0) {
					printf("%s\n", buf);
				}
			}
		}
	}
}
static void print_files_in_dir ( const char * dir , const char * extension ) { int i , count = 0 ; struct dirent * * files = NULL ; count = scandir ( dir , & files , 0 , alphasort ) ; if ( count < 0 ) { fprintf ( stderr , " " ) ; perror ( dir ) ; exit ( 1 ) ; } for ( i = 0 ; i < count ; ++ i ) { if ( ( strcmp ( files [ i ] -> d_name , " " ) != 0 ) && ( strcmp ( files [ i ] -> d_name , " " ) != 0 ) ) { char buf [ 1024 ] ; char * extn = NULL ; sprintf ( buf , " " , files [ i ] -> d_name ) ; extn = strrchr ( buf , ' ' ) ; if ( extn && strcmp ( extn , extension ) == 0 ) { * extn = ' \0 ' ; if ( strlen ( buf ) > 0 ) { printf ( " \n " , buf ) ; } } } } }
Print a sorted list of files in the directory 'dir' whose extension is 'extn'
Print a sorted list of files in the directory ' dir ' whose extension is ' extn '
/* Get a sorted directory list */ /* file extension */ /* Now buf holds the file name without the extension */