home *** CD-ROM | disk | FTP | other *** search
/ Netware Super Library / Netware Super Library.iso / file_mgt / file_age / fileage.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  2.0 KB  |  77 lines

  1. #include <classlib\time.h>
  2. #include <cstring.h>
  3. #include <dos.h>
  4. #include <iostream.h>
  5. #include <stdio.h>
  6.  
  7. // FileAge.Exe / Author: David H. Bennett / Date: 5-3-95 / Version: 1.0
  8. //
  9. // Returns the age of a file in Minutes, Hours, or Days as an
  10. // errorlevel.
  11. //
  12. // CIS: 74635,1671
  13. // Internet: bss@bensoft.com
  14.  
  15. // Error Levels
  16. //    0-119   -  Minutes Old
  17. //  120-166   -  Hours Old-118
  18. //  167-253   -  Days Old-165
  19. //  254       -  More than 88 Days old
  20. //  255       -  ERROR
  21.  
  22. char *strUsage="Usage: FILEAGE [[drive:][path]filename[ ...]]\n" \
  23.     "\n" \
  24.     "Returns the age of the file in Minutes, Hours, or Days as an\n" \
  25.     "errorlevel.\n" \
  26.     "\n" \
  27.     "Error Levels Returned:\n" \
  28.     "\n" \
  29.     "      0-119   - Minutes Old\n" \
  30.     "    120-166   - Hours Old-118\n" \
  31.     "    167-253   - Days Old-165\n" \
  32.     "        254   - More than 88 Days old\n" \
  33.     "        255   - ERROR\n" \
  34.     "\n" \
  35.     "Author: David H. Bennett / Date: 5-3-95 / Version: 1.0\n";
  36.  
  37. int main(int argc, char* argv[])
  38. {
  39.     FILE *stream;
  40.     unsigned iFDay, iFMonth, iFYear, iFMin, iFHour;
  41.     unsigned iFDate, iFTime;
  42.  
  43.     if (argc<=1) {
  44.         cout << strUsage;
  45.         return(255);
  46.     }
  47.  
  48.     if ((stream = fopen(argv[1], "r")) == NULL)
  49.     {
  50.         return 255;
  51.     }
  52.     _dos_getftime(fileno(stream), &iFDate, &iFTime);
  53.     fclose(stream);
  54.  
  55.     iFDay=(iFDate & 0x1F);
  56.     iFMonth=((iFDate >> 5) & 0xF);
  57.     iFYear=(((iFDate >> 9) & 0x7F) + 1980);
  58.     iFMin=((iFTime >> 5) & 0x3F);
  59.     iFHour=((iFTime >> 11) & 0x1F);
  60.  
  61.     {
  62.         unsigned long ulSeconds, ulMinutes, ulHours, ulDays;
  63.         TDate tdFile(iFDay,iFMonth,iFYear);
  64.         TTime ttFile(tdFile,iFHour,iFMin,0);
  65.         TTime ttNow;
  66.         ulSeconds=ttNow.Seconds()-ttFile.Seconds();
  67.         ulMinutes=ulSeconds / 60;
  68.         ulHours=ulMinutes / 60;
  69.         ulDays=ulHours / 24;
  70.  
  71.         if (ulMinutes <= 101) return (int)ulMinutes;
  72.         if (ulHours <= 48) return (int)((int)ulHours+118);
  73.         if (ulDays <= 88)  return (int)((int)ulDays+165);
  74.     }
  75.   return(254);    // Older than Resolution
  76. }
  77.