home *** CD-ROM | disk | FTP | other *** search
- /* ------------------------------------------------- */
- /* size.c */
- /* gibt die Größe von Dateien aus */
- /* ------------------------------------------------- */
-
- #include <stdio.h>
- #include <dos.h>
-
- char attr[8][9] = {
- " r/o",
- " hidden",
- " system",
- " volume",
- " subdir",
- " archive",
- " n/a",
- " n/a"
- };
-
- char *index();
-
- int isubdir( s )
- char s[];
- {
- if(((strlen(s) == 1) && (s[0] == '.')) ||
- ((strlen(s) == 2) && (s[0] == '.') &&
- (s[1] == '.')))
- return 1;
- else
- return 0;
- } /* isubdir */
-
- main( argc,argv )
- int argc;
- char *argv[];
- {
- char *pattern; /* files to match */
- char dispsw = 1; /* disp all files, def. on */
- long total = 0; /* total size of files */
- int files = 0; /* no of files */
- long size; /* size of each file */
- int i;
- char mc; /* attr */
- char as[40]; /* attr str */
- struct FIND *p; /* dir entry */
- char fname[9],ext[4]; /* filename */
- char *point;
-
- if(argc > 1)
- {
- for(i = argc; i > 0; i--)
- {
- if(*argv[i] == '-')
- {
- switch(*(argv[i]+1))
- {
- case 'n' :
- case 'N' : dispsw = 0;
- break;
- }
- }
- else pattern = argv[i];
- } /* for .. */
-
- p = findfirst( pattern, 0xff );
- while(p != NULL)
- {
- size = p->size;
- total += size;
- files++;
- as[0] = 0;
- for(mc = 0; mc < 8; mc++)
- {
- if((p->attribute & (1 << mc)) != 0)
- strcat(as,attr[mc]);
- }
- if(dispsw == 1)
- {
- if(((point = index(p->name,'.')) != NULL) &&
- (isubdir( p->name ) == 0 ))
- {
- strncpy(fname, p->name, point - p->name);
- fname[point - p->name] = '\0';
- strncpy(ext, ++point, 4);
- if((p->attribute & 0x10) == 0x10)
- fprintf(stdout, "\n%-8s %-6s <DIR> %s",
- fname, ext, as);
- else
- fprintf(stdout, "\n%-8s %-3s %8ld %s",
- fname, ext, size, as);
- }
- else
- fprintf(stdout, "\n%-15s <DIR> %s",
- p->name, as);
- }
- p = findnext();
- } /* while .. */
- if( total != 0 )
- fprintf(stdout,
- "\n\nTotal: %14ld Bytes %5d File(s)\n",
- total,files);
- } /* if argc > 1 */
- } /* main */
- /* ------------------------------------------------- */
- /* Ende von size.c */