04-20-04 06:34 PM
Needs to be converted to return char**, but this is what I use.
#include <dirent.h>
#include <regexpr.h>
#include <stdio.h>
#include <stdlib.h>
HashTable* ListDirectory(String& in,char* regx)
{
DIR *dirp;
struct dirent *dp;
HashTable* files;
char *expbuf=NULL;
if (in.IsEmpty())
{
lERROR("Received null pointer. Expected char*.");
return NULL;
}
files = new HashTable;
dirp = opendir(in.Get());
if (dirp EQ NULL)
{
lERROR_A("Unable to open directory \"%s\".",in.Get());
return NULL;
}
while ( (dp = readdir( dirp )) != NULL )
{
if (regx EQ NULL) files->Put(dp->d_name,(void*)NULL);
else
if ((expbuf = compile(regx,(char*)0,(char*)0)))
if (step(dp->d_name,expbuf)) files->Put(dp->d_name,(void*)NULL);
free(expbuf);
}
closedir( dirp );
return files;
}
/*
main (void)
{
int i;
list_directory(".",&i,".*\\.c$");
}
*/
Ondras wrote:
> Do you know how to make 'ls' command in C without using functions from
> standart libraries? I can use only printf, scanf and functions
> implemented in man getpwnam and man getgrnam.
> Thanx a lot.
--
___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodlogy Group
Dallas, Texas, 214-480-4455, b-patton@ti.com
[ Post a follow-up to this message ]
|