home *** CD-ROM | disk | FTP | other *** search
- /////////////////////////////////////////////////////////////////
- // This Task file searches a defined directory for specific files
- // which have not been accessed in more than a defined number of
- // days. Files matching the criteria are then deleted.
- /////////////////////////////////////////////////////////////////
-
-
- // Change to the following Volume:Directory to search for matching files
-
- CD SYS:DATABASE
-
-
- // Variables used:
- //
- // %7 : Year of latest allowed access date
- // %8 : Month of latest allowed access date
- // %9 : Day of latest allowed access date
-
- // Pre-Define the base values
-
- DEFINE %7 %YEAR%
- DEFINE %8 %MONTH%
- DEFINE %9 %DAY%
-
-
- // Calculate the last access date possible without deletion.
- // This calculation process will use some of the temporary
- // variables to build the appropriate date. Unless today
- // happens to be greater than the 14th of the month, the
- // conversion requires a little bit of logic.
- // (Note: This logic checks if a file has been accessed
- // within the last 14 days, i.e., 2 weeks. If a
- // different time period is desired, all of the %9
- // calculations need to be adjusted accordingly.
- // Different logic will be required if the factor is
- // greater than 28 days - i.e., more than 4 weeks.)
-
- IF %9<15
- IF %8==01 // special - adj year also
- DEFINE %9 %9+=17
- DEFINE %8 12
- DEFINE %7 %7-=1
- ELSEIF %8==03 // prev month = 28 days
- DEFINE %9 %9+=14
- DEFINE %8 %8-=1
- ELSEIF %8==05 OR %8==07 OR %8==10 OR %8=12 // prev month = 30 days
- DEFINE %9 %9+=16
- DEFINE %8 %8-=1
- ELSE // prev month = 31 days
- DEFINE %9 %9+=17
- DEFINE %8 %8-=1
- ENDIF
- ELSE // %DAY% > 14 so sub 14
- DEFINE %9 %9-=14
- ENDIF
-
-
- // Open an output file to log what action is taken
-
- OPEN_WRITE SYS:SYSTEM\DB_PURGE.DAT
-
-
- // Write a null line to separate previous entries
-
- WRITE
-
-
- // Echo and Write a header identifying this action
-
- ECHO_WRITE %TASK_NAME% started on %MONTH%/%DAY%/%YEAR% at %HOUR%:%MINUTE%%AM_PM%
-
-
- // Variables used:
- //
- // %0 : Next matching file in search
- // %7 : Year of latest allowed access date (previously calculated)
- // %8 : Month of latest allowed access date (previously calculated)
- // %9 : Day of latest allowed access date (previously calculated)
-
-
- // Check if any .DB files exist in this directory
-
- IF EXIST *.DB
-
-
- // Define variable %0 as the first matching
- // file in the search
-
- DEFINE %0 %DIR_FILE_*.DB%
-
-
- // For file checking, uses a WHILE/LOOP which
- // loops while %0 is defined
-
- WHILE "%0">""
-
-
- // Check if last access date for %0 is less than defined date
- // (Note: %FILE_ACCESS_% format = yyyy/mm/dd)
-
- IF "%FILE_ACCESS_%0%"<"%7/%8/%9"
-
-
- // Echo/Write a message on what we're about to do
-
- ECHO_WRITE %0 (Owner: %FILE_OWNER_%0%) deleted!
-
-
- // It has not been accessed recently so
- // First we'll FLAG it RW -DI -RI...
-
- FLAG %0 rw
-
-
- // Then we'll delete it!
-
- DEL %0
-
-
- // End of %FILE_ACCESS_% check structure
-
- ENDIF
-
-
- // Get the next matching file
-
- DEFINE %0 %DIR_FILE_%
-
-
- // Repeat the process
-
- LOOP
-
-
- // End of IF EXIST *.DB structure
-
- ENDIF
-
-
- // Close the output file (not required since TaskMaster will
- // cleanup after a Task but shows good design and structure)
-
- CLOSE