If you save inbound/outbound documents for Archiving and sometimes forget to go back and weed out the older ones, here's a way to take care of that by adding this to the end of your Project.
It's a cleanup utility Project that will take 2 parameters ( RetainDays & CleanDIR )
RetainDays = Number of days for Cutoff of documents to retain.
CleanDIR = The root Directory that you want to start cleaning from.
The Project is recursive, so the cleanup will process all sub-folders under the "CleanDir" location as well.
This utility will also print a list of the files removed for reference.
I usually just call this from a Project Module (as in):
Code: Select all
<project>
<module name="Main">
...
<callModule module="Cleanup" label="(Module) Cleanup" version="1.0" />
...
</module>
<module name="Cleanup" description="Clean up Older Documents from Archive">
<callProject label="Cleanup Archive Docs" project="/Utilities/Cleanup Archive Docs" runInSameJob="true" inheritUserVariables="true" version="1.0">
<variable name="RetainDays" value="${ RetainDays }" />
<variable name="CleanDIR" value="${ DirectorDIR }" />
</callProject>
</module>
</project>
Code: Select all
<project name="Cleanup Archive Docs" mainModule="Main" version="2.0" logLevel="debug" onError="call:Error Handler">
<!-- Passed Parms -->
<variable name="RetainDays" value="60" description="No of Days to retain (Default = 60)" />
<variable name="CleanDIR" value="" description="Directory to Clean" />
<module name="Main">
<if label="Check RetainDays Value" condition="${ ( RetainDays eq system.emptyString ) or ( RetainDays eq 0 ) }">
<print label="(Status) Invalid RetainDays" version="1.0">
<![CDATA[
*===============================================================================*
*** Cleaning Up Archive ***
"RetainDays" Parameter must be Greater than Zero.
Change value and retry.
*===============================================================================*
]]>
</print>
<exitModule/>
</if>
<if label="Check CleanDIR Value" condition="${ CleanDIR eq system.emptyString }">
<print label="(Status) Invalid CleanDIR" version="1.0">
<![CDATA[
*===============================================================================*
*** Cleaning Up Archive ***
"CleanDIR" Parameter must not be blank.
Change value to a valid directory and retry.
*===============================================================================*
]]>
</print>
<exitModule/>
</if>
<!-- Get Cutoff Date -->
<timestamp label="Set TimeStamp" version="1.0">
<format outputVariable="CutOffDate" pattern="yyyy-MM-dd" dayOfMonth="-${ RetainDays }" />
</timestamp>
<print label="(Status) Cleanup Cutoff" version="1.0">
<![CDATA[
*===============================================================================*
* Clean Dir: ${ CleanDIR }
* CutOff Date: ${ CutOffDate } -- Removing files over ${ RetainDays } Days Old
*===============================================================================*
]]>
</print>
<!-- Get list of files to be removed -->
<createFileList label="Get Files to Remove" fileListVariable="RemoveFiles" numFilesFoundVariable="NoFiles" version="1.0">
<fileset dir="${ CleanDIR }" recursive="true">
<dateFilter>
<include to="${ CutOffDate }" />
</dateFilter>
</fileset>
</createFileList>
<!-- Remove files - Generate File Removal List -->
<setVariable label="Set FileList" name="FileList" value="${ system.emptyString }" version="1.0" />
<forEachLoop label="Remove Outdated Files" itemsVariable="${RemoveFiles}" currentItemVariable="ThisFile">
<setVariable label="Get FileList" name="FileList" value="${ FileList }${ system.carriageReturn }Removing ${ ThisFile:name } - ${ ThisFile:lastModifiedDate }" version="1.0" />
<delete label="Remove File" file="${ ThisFile }" version="1.0" />
</forEachLoop>
<print label="(Status) Cleanup List" version="1.0">
<![CDATA[
*===============================================================================*
* Clean Dir: ${ CleanDIR }
*===============================================================================*
${ FileList }
*===============================================================================*
${ NoFiles } file(s) removed
*===============================================================================*
]]>
</print>
</module>
<module name="Error Handler" description="Handle Process Errors">
<timestamp label="Set TimeStamp" version="1.0">
<format outputVariable="DateSent" pattern="yyyy-MM-dd" />
<format outputVariable="TimeSent" pattern="hh:mm:ss" />
</timestamp>
<print label="Error Status" version="1.0">
<![CDATA[
*================================================*
*************** ERROR HANDLER ********************
*================================================*
* Job Step: ** Process Error **
* Date: ${DateSent}
* Time: ${TimeSent}
* Error: ${system.job.error}
*================================================*
]]>
</print>
</module>
<description>Cleanup Archive Directory</description>
</project>
As always .. if you have any questions, please let me know.
-Rick