home *** CD-ROM | disk | FTP | other *** search
/ Netware Super Library / Netware Super Library.iso / timevent / taskmstr / oldfiles.tsk < prev    next >
Encoding:
Text File  |  1995-05-07  |  3.7 KB  |  144 lines

  1. /////////////////////////////////////////////////////////////////
  2. // This Task file searches a defined directory for specific files
  3. // which have not been accessed in more than a defined number of
  4. // days.  Files matching the criteria are then deleted.
  5. /////////////////////////////////////////////////////////////////
  6.  
  7.  
  8. // Change to the following Volume:Directory to search for matching files
  9.  
  10. CD SYS:DATABASE
  11.  
  12.  
  13. // Variables used:
  14. //
  15. //   %7 : Year of latest allowed access date
  16. //   %8 : Month of latest allowed access date
  17. //   %9 : Day of latest allowed access date
  18.  
  19. // Pre-Define the base values
  20.  
  21. DEFINE %7 %YEAR%
  22. DEFINE %8 %MONTH%
  23. DEFINE %9 %DAY%
  24.  
  25.  
  26. // Calculate the last access date possible without deletion.
  27. // This calculation process will use some of the temporary
  28. // variables to build the appropriate date.  Unless today
  29. // happens to be greater than the 14th of the month, the
  30. // conversion requires a little bit of logic.
  31. // (Note: This logic checks if a file has been accessed
  32. //        within the last 14 days, i.e., 2 weeks.  If a
  33. //        different time period is desired, all of the %9
  34. //        calculations need to be adjusted accordingly.
  35. //        Different logic will be required if the factor is
  36. //        greater than 28 days - i.e., more than 4 weeks.)
  37.  
  38. IF %9<15
  39.     IF %8==01                                         // special - adj year also
  40.         DEFINE %9 %9+=17
  41.         DEFINE %8 12
  42.         DEFINE %7 %7-=1
  43.     ELSEIF %8==03                                     // prev month = 28 days
  44.         DEFINE %9 %9+=14
  45.         DEFINE %8 %8-=1
  46.     ELSEIF %8==05 OR %8==07 OR %8==10 OR %8=12        // prev month = 30 days
  47.         DEFINE %9 %9+=16
  48.         DEFINE %8 %8-=1
  49.     ELSE                                              // prev month = 31 days
  50.         DEFINE %9 %9+=17
  51.         DEFINE %8 %8-=1
  52.     ENDIF
  53. ELSE                                                  // %DAY% > 14 so sub 14
  54.     DEFINE %9 %9-=14
  55. ENDIF
  56.  
  57.  
  58. // Open an output file to log what action is taken
  59.  
  60. OPEN_WRITE SYS:SYSTEM\DB_PURGE.DAT
  61.  
  62.  
  63. // Write a null line to separate previous entries
  64.  
  65. WRITE
  66.  
  67.  
  68. // Echo and Write a header identifying this action
  69.  
  70. ECHO_WRITE %TASK_NAME% started on %MONTH%/%DAY%/%YEAR% at %HOUR%:%MINUTE%%AM_PM%
  71.  
  72.  
  73. // Variables used:
  74. //
  75. //   %0 : Next matching file in search
  76. //   %7 : Year of latest allowed access date             (previously calculated)
  77. //   %8 : Month of latest allowed access date            (previously calculated)
  78. //   %9 : Day of latest allowed access date              (previously calculated)
  79.  
  80.  
  81. // Check if any .DB files exist in this directory
  82.  
  83. IF EXIST *.DB
  84.  
  85.  
  86.     // Define variable %0 as the first matching
  87.     // file in the search
  88.  
  89.     DEFINE %0 %DIR_FILE_*.DB%
  90.  
  91.  
  92.     // For file checking, uses a WHILE/LOOP which
  93.     // loops while %0 is defined
  94.  
  95.     WHILE "%0">""
  96.  
  97.  
  98.         // Check if last access date for %0 is less than defined date
  99.         // (Note: %FILE_ACCESS_% format = yyyy/mm/dd)
  100.  
  101.         IF "%FILE_ACCESS_%0%"<"%7/%8/%9"
  102.  
  103.  
  104.             // Echo/Write a message on what we're about to do
  105.  
  106.             ECHO_WRITE %0 (Owner: %FILE_OWNER_%0%) deleted!
  107.  
  108.  
  109.             // It has not been accessed recently so
  110.             // First we'll FLAG it RW -DI -RI...
  111.  
  112.             FLAG %0 rw
  113.  
  114.  
  115.             // Then we'll delete it!
  116.  
  117.             DEL %0
  118.  
  119.  
  120.         // End of %FILE_ACCESS_% check structure
  121.  
  122.         ENDIF
  123.  
  124.  
  125.         // Get the next matching file
  126.  
  127.         DEFINE %0 %DIR_FILE_%
  128.  
  129.  
  130.     // Repeat the process
  131.  
  132.     LOOP
  133.  
  134.  
  135. // End of IF EXIST *.DB structure
  136.  
  137. ENDIF
  138.  
  139.  
  140. // Close the output file (not required since TaskMaster will
  141. // cleanup after a Task but shows good design and structure)
  142.  
  143. CLOSE
  144.