///////////////////////////////////////////////////////////////////// // // This Task will traverse the specified directory tree and delete // all files in the tree, except for those directories which match // the specified name/pattern (DEFINE %9). // // Note: Search for {MODIFY} comments indicating items which need // to be modified or renamed (as appropriate). // ///////////////////////////////////////////////////////////////////// // // Variables used: // // %0 : Server Console (base) Current Working Directory (CWD) // %1 : CWD being processed (traverses %DIR_TREE_% tree) // %2 : File in CWD to check (loops through %DIR_FILE_% list) // %3 : Number of directories processed // %4 : Number of directories skipped // %9 : Directory name to skip/bypass (optional) // // Define the %9 variable as the directory name to skip. // Use leading and trailing backslashes to insure that // the subdirectory (and subdirectories under it) are // skipped but not directories whose name happens to // start with this variable name (refer to examples). // (Note: DOS format, case sensitive) // // Example 1: // DEFINE %9 // Note: This line can also be deleted since // the undefined default is a null value. // // results: // \PUBLIC\NLS (processed) // \PUBLIC\NLS\ENGLISH (processed) // \PUBLIC\NLS.OLD (processed) // \PUBLIC\NLSNAMES (processed) // \LOGIN\NLS (processed) // \LOGIN\NLS\ENGLISH (processed) // \LOGIN\NLS.OLD (processed) // \LOGIN\NLSNAMES (processed) // // Example 2: // DEFINE %9 \NLS\ // // results: // \PUBLIC\NLS (skipped) // \PUBLIC\NLS\ENGLISH (skipped) // \PUBLIC\NLS.OLD (processed) // \PUBLIC\NLSNAMES (processed) // \LOGIN\NLS (skipped) // \LOGIN\NLS\ENGLISH (skipped) // \LOGIN\NLS.OLD (processed) // \LOGIN\NLSNAMES (processed) // // Example 3: // DEFINE %9 \NLS // // results: // \PUBLIC\NLS (skipped) // \PUBLIC\NLS\ENGLISH (skipped) // \PUBLIC\NLS.OLD (skipped) // \PUBLIC\NLSNAMES (skipped) // \LOGIN\NLS (skipped) // \LOGIN\NLS\ENGLISH (skipped) // \LOGIN\NLS.OLD (skipped) // \LOGIN\NLSNAMES (skipped) // // Example 4: // DEFINE %9 \LOGIN\NLS // // results: // \PUBLIC\NLS (skipped) // \PUBLIC\NLS\ENGLISH (skipped) // \PUBLIC\NLS.OLD (skipped) // \PUBLIC\NLSNAMES (skipped) // \LOGIN\NLS (processed) // \LOGIN\NLS\ENGLISH (processed) // \LOGIN\NLS.OLD (processed) // \LOGIN\NLSNAMES (processed) // // Example 5: // DEFINE %9 \LOGIN\NLS\ // // results: // \PUBLIC\NLS (skipped) // \PUBLIC\NLS\ENGLISH (skipped) // \PUBLIC\NLS.OLD (skipped) // \PUBLIC\NLSNAMES (skipped) // \LOGIN\NLS (processed) // \LOGIN\NLS\ENGLISH (processed) // \LOGIN\NLS.OLD (skipped) // \LOGIN\NLSNAMES (skipped) // ///////////////////////////////////////////////////////////////////// // Open an log file to log what action is taken OPEN_WRITE SYS:SYSTEM\PRUNE.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% // save the current working directory DEFINE %0 %CWD% // Starting point (base directory from which to start processing) // {MODIFY} Change VOL:\ to the appropriate base directory starting point CD VOL:\ // number of directories processed DEFINE %3 0000 // number of directories skipped DEFINE %4 0000 // number of files processed DEFINE %5 0000 // number of files deleted DEFINE %6 0000 // If defined (not commented out), defines a directory name/pattern to skip // {MODIFY} Optional directory pattern to bypass // DEFINE %9 // WHILE/LOOP provides continuous processing while %DIR_TREE_% // continues to return a valid directory path WHILE // Define the next matching entry in the directory tree // If this is the first directory checked, we must provide // a starting point to work from (. specifies the CWD) IF "%1"=="" DEFINE %1 %DIR_TREE_.% ELSE DEFINE %1 %DIR_TREE_% ENDIF // Was an excluded directory name defined? IF NOT "%9"=="" // Check for the excluded subdirectory specification WHILE SCAN_STRING "%9" "%CWD%\" ECHO_WRITE %CWD% (skipped) DEFINE %1 %DIR_TREE_% DEFINE %4 %4+=1 LOOP ENDIF // Has the entire tree been traversed (NULL return)? IF "%1"=="" THEN BREAK // Process this directory ECHO_WRITE %CWD% (processed) // Increment the Directories Processed counter DEFINE %3 %3+=1 // Do any files exist in this directory? IF EXIST *.* DEL *.* // End of IF EXIST *.* structure ENDIF // Continue the directory tree processing LOOP // Display a summary of the results ECHO_WRITE. ECHO_WRITE Finished pruning %CWD% ... ECHO_WRITE Directories: %3 processed / %4 skipped // Reset the original Server Console Current Working Directory (CWD) CD %0 CLOSE