/* fs.c * * fs [-h -s -p -t -f -ad -d -lnnn -v] path * * h - help * s - scan subdirectory * p - prompt when screen is full * t - show totals only * f - report only matching files * ad - show how much files will use on drive d: * d - show all directory entries * l - minimum file size to show * v - verify file name * * Written by: Eyal Lebedinsky * Date: 29 May 1988 * * file size utility. will report size of file and amount of slack for all * files in path and optionally all subdirectory. path can contain a file * name with wild-characters to select files. detail lines show the file name * followed by file size and disk space used by the file. totals line shows * totals for above and % unused space. the directory structure is shown as * indentation. * * examples: * * >fs /s *.rep ---- show size for all file with extension 'rep' in current * directory and subdirectories. * >fs/fs \xyz\*.rep ---- list any file in 'xyz' directory or any subdirectory * with extention 'rep'. * >fs d:\read.me /f /s ---- find all files called 'read.me' in drive d: * >fs *.* /aa /t ---- show how much space my files will take on a floppy. * >fs /aa /t ---- as above. no file defaults to '*.*' * >fs ---- directory list. * >fs /p ---- as above with pause at every screenfull. * * 28 Aug 93: add option l, v. */ #include #include #include #include #include static int option_t, option_s, option_p, option_f, option_a, option_d; static int option_h, option_l, option_v; static char temp_name[80], root[80], odir[80]; static int line_no, cnt; static long csize, asize, l1, l2, l3, min_size; static struct diskfree_t diskfree; static void indent (i) register int i; { if (option_p) { if (line_no >= 24) { printf ("Any key to continue"); getch (); putch ('\r'); line_no = 1; } else ++line_no; } if (option_f) { printf ("%s", root); return; } while (i--) printf (" "); } static int bad_filename (struct find_t *dir_entry, int depth) { int i, c; for (i = 0; i < 12 && 0 != (c = dir_entry->name[i]); ++i) { if ((c > 0 && c < 32) || c >= 128) { indent (depth); printf ("%-13.13s \n", dir_entry->name, i, (unsigned char)c); return (1); } } if (0 == i) { indent (depth); printf ("%-13.13s \n", ""); return (1); } return (0); } static void list_dir (file, depth, totals) char *file; int depth; long totals[3]; { struct find_t dir_entry; long total[4], last_total; int eod, len; len = strlen (root); if (!option_f) { indent (depth++); printf ("%s\n", root); } total[0] = total[1] = total[2] = total[3] = 0L; strcpy (root + len, file); for (eod = _dos_findfirst (root, 0xffff, &dir_entry), root[len] = '\0', cnt = 0; !eod; eod = _dos_findnext (&dir_entry)) { if (option_v) { totals[2] += bad_filename (&dir_entry, depth); continue; } if (!(dir_entry.attrib & (_A_SUBDIR | _A_VOLID))) { if (option_l && dir_entry.size <= min_size) ; else { total[0] += l1 = dir_entry.size; total[1] += l2 = ((dir_entry.size + csize - 1L) / csize) * csize; if (option_a) total[3] += l3 = ((dir_entry.size + asize - 1L) / asize) * asize; ++cnt; if (!option_t) { indent (depth); printf ("%-13.13s %8lu %8lu\n", dir_entry.name, l1, l2); } } } else if (option_d && !option_t && !(option_s && (dir_entry.attrib & _A_SUBDIR))) { indent (depth); printf ("%-13.13s %8s\n", dir_entry.name, dir_entry.attrib & _A_SUBDIR ? "" : "