home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 4
/
DATAFILE_PDCD4.iso
/
unix
/
unixtools
/
ls
/
ls_c
< prev
Wrap
Text File
|
1992-07-21
|
1KB
|
77 lines
static char sccs_id[] = "@(#) ls.c (c) James Noad 12-April-1991";
#include <stdio.h>
#include <dirent.h>
#include <sys/dirent.h>
int showdir(char *dir);
int main(int argc,char **argv)
{
DIR *currdir;
struct direct *ch;
int objects = 0,size = 0, tmp,tmpp;
int count = 0, grandcount = 0;
if(argc < 2)
{
printf("\nDirectory %s contains %d objects\n", "@", showdir("@"));
return(0);
}
for(tmpp=1;tmpp<argc;tmpp++)
{
if((count = showdir(argv[tmpp])) < 0)
{
count = 0;
printf("Can't open directory %s\n",argv[tmpp]);
}
else
{
printf("\nDirectory %s contains %d objects\n", argv[tmpp], count);
grandcount = grandcount + count;
}
}
if(argc > 2)
{
printf("Grand total of %d objects\n",grandcount);
}
return(0);
}
int showdir(char *dir)
{
DIR *currdir;
struct direct *ch;
int tmp,objects = 0;
printf("\n");
if((currdir = opendir(dir)) == NULL)
{
return(-1);
}
while((ch = readdir(currdir)) != NULL)
{
objects++;
printf("%s",ch->d_name);
if(!(objects % 7))
{
printf("\n");
}
else
{
for(tmp = MAXNAMLEN - strlen(ch->d_name) + 1; tmp > 0; tmp--)
{
printf(" ");
}
}
}
if(objects % 7)
{
printf("\n");
}
closedir(currdir);
return(objects);
}