/* This unfinished work will when finished scan all drives on a system for files that have dates that fall between a given date range. As it is it scans for files on a given drive from the current subdirectory forward. */ #include #include #include #include #define MOST FA_NORMAL | FA_RDONLY | FA_HIDDEN | FA_SYSTEM | FA_ARCH #define ALL FA_NORMAL | FA_RDONLY | FA_HIDDEN | FA_SYSTEM | FA_ARCH | FA_DIREC #define TRUE 0 #define FALSE -1 unsigned peak_date, base_date, tmp_date, sense; main(argc, argv) int argc; char *argv[]; { struct ffblk fdat; struct date sdat; int ctp, month, day, year; char curdir[256], date_str1[20], date_str2[20]; getcwd(curdir, 238); if (strlen(&curdir) > 3) strcat(curdir, "\\"); getdate(&sdat); base_date = sdat.da_year - 1900; if (sdat.da_year >= 2000) base_date -= 100; if (base_date >= 80) /* Time starts at 1980 but 2000 truncates to 00 */ base_date -= 80; else base_date += 20; base_date &= 0x007f; base_date = base_date << 9; base_date |= ((int) sdat.da_mon) << 5; base_date |= (int) sdat.da_day; if (argc != 3) { usage(); return; } if ((strcmp(argv[1], ".") != 0) && (strcmp(argv[1], "+") != 0) && (strcmp(argv[1], "-") != 0)) { if (mdy_fdate(&base_date, argv[1]) == FALSE) { usage(); return; } if (mdy_fdate(&peak_date, argv[2]) == FALSE) { usage(); return; } } else { if (strcmp(argv[1], ".") == 0) { if (mdy_fdate(&peak_date, argv[2]) == FALSE) { usage(); return; } } if (strcmp(argv[1], "-") == 0) { sscanf(argv[2], "%d", &day); peak_date = base_date - day; } if (strcmp(argv[1], "+") == 0) { sscanf(argv[2], "%d", &day); peak_date = base_date + day; } } if (base_date > peak_date) { tmp_date = peak_date; peak_date = base_date; base_date = tmp_date; } if (findfirst("*.*", &fdat, ALL) == 0) { fdate_mdy(base_date, date_str1); fdate_mdy(peak_date, date_str2); printf("\nLooking for files from %s to %s \n", date_str1, date_str2); chknext(&fdat, curdir); }else { usage(); return; } } mdy_fdate(fdt, mdy) int *fdt; char *mdy; { int ctp, month, day, year; ctp = 0; while ((isdigit( mdy [ctp]) == 0) && ctp < 25) ctp++; month = mdy[ctp] - 0x30; ctp++; if (isdigit(mdy[ctp])) { month = month * 10 + (mdy[ctp] - 0x30); ctp++; } while ((isdigit(mdy[ctp]) == 0) && ctp < 25) ctp++; day = mdy[ctp] - 0x30; ctp++; if (isdigit(mdy[ctp])) { day = day * 10 + (mdy[ctp] - 0x30); ctp++; } while ((isdigit(mdy[ctp]) == 0) && ctp < 25) ctp++; year = mdy[ctp] - 0x30; ctp++; if (isdigit(mdy[ctp])) { year = year * 10 + (mdy[ctp] - 0x30); } if (month > 12 || month < 1) return FALSE; if (day > 31 || day < 1) return FALSE; if (year > (127 + 80)) return FALSE; if (year >= 80) /* Time starts at 1980 but 2000 is entered as zero zero */ year -= 80; else year += 20; year &= 0x007f; *fdt = 0; *fdt |= (year << 9); *fdt |= (month << 5); *fdt |= day; return TRUE; } fdate_mdy(fdt, mdy) int fdt; char *mdy; { if (((fdt >> 9) & 0x007f) >= 20) { /* case for after 2000 */ sprintf(mdy, "%02d-%02d-%02d", (fdt >> 5) & 0x000f, fdt & 0x001f, ((fdt >> 9) & 0x007f) - 20); } else { /* case for 1980 to 1999 */ sprintf(mdy, "%02d-%02d-%02d", (fdt >> 5) & 0x000f, fdt & 0x001f, ((fdt >> 9) & 0x007f) + 80); } } ftime_hms(ftm, hms) int ftm; char *hms; { sprintf(hms, "%02d:%02d:%02d", (ftm >> 11) & 0x1f, (ftm >> 5) & 0x3f, (ftm & 0x1f) * 2); } usage() { clrscrn(); printf("ÚÄÄ ÂÄÄ¿ ÂÄÄ¿ Given free of charge by Jim Phillips \n"); printf("ÃÄÄ ³ ³ ÃÄÂÙ \n"); printf("Á ÁÄÄÙ Á \\ \n"); printf("File Date Range \n"); printf(" \n"); printf("Usage: fdr 5-25-96 10-2-96 \n"); printf(" \n"); printf("would search from the current drive and directory recursing \n"); printf("through all directories below that point and list all files \n"); printf("that fall between those dates.\n"); printf(" \n"); printf("You are limited to pairs of digits, I.E. the first day of \n"); printf("the year 2000 is entered as 1-1-00 \n"); printf(" \n"); printf("Atlernative Usage:\n"); printf("Use: fdr . 10-22-96 Searches from current date to 10-22-96\n"); printf("Use: fdr + 365 Searches from current "); printf("date forward one year.\n"); printf("Use: fdr - 7 Searches from one week ago to present.\n"); printf(" \n"); printf("Note: this is beta release... version - 1.01 \n"); printf(" \n"); printf("Thanks to Rich Ottosen for suggesting the time stamp feature.\n"); } chknext(fdat, dirnam) struct ffblk *fdat; char *dirnam; { struct ffblk l_fdat; char l_dirnam[256], date_str[20], time_str[20]; do { if (chkdots(fdat) == TRUE) continue; if (chkdates(fdat) == TRUE) { fdate_mdy((*fdat).ff_fdate, date_str); ftime_hms((*fdat).ff_ftime, time_str); if (((*fdat).ff_attrib & FA_DIREC) == FA_DIREC) { printf("%s%s %s %s\n", dirnam, (*fdat).ff_name, date_str, time_str); }else { printf("%s%s %ld %s %s\n", dirnam, (*fdat).ff_name, (*fdat).ff_fsize, date_str, time_str); } } if (((*fdat).ff_attrib & FA_DIREC) == FA_DIREC) { strncpy(l_dirnam, dirnam, 238); strncat(l_dirnam, (*fdat).ff_name, 12); strcat(l_dirnam, "\\"); chdir((*fdat).ff_name); if (findfirst("*.*", &l_fdat, ALL) == 0) { chknext(&l_fdat, l_dirnam); } chdir(".."); continue; } } while (findnext(fdat) == TRUE); } chkdots(fdat) struct ffblk *fdat; { if ((((*fdat).ff_attrib & FA_DIREC) == FA_DIREC) && ((strcmp(&(*fdat).ff_name, ".") == 0) || (strcmp(&(*fdat).ff_name, "..") == 0))) return TRUE; else return FALSE; } chkdates(fdat) struct ffblk *fdat; { if (((*fdat).ff_fdate >= base_date) && ((*fdat).ff_fdate <= peak_date)) return TRUE; else return FALSE; }