Page 1 of 1

Move files newly created files from an existing folder

Posted: Wed Oct 22, 2014 9:45 am
by intl_sp
We have this requirement to move newly created files from an Archive folder that contains files from over a year.

While doing so, is their a way to completely avoid the ForEachLoop ?
We are working under restrictions for e.g we cannot modify the existing folder structure.

I am aware that a monitor can be used to detect new files, but how can the job decide which files are created say 'today' and transfer only those?

Re: Move files newly created files from an existing folder

Posted: Fri Oct 24, 2014 11:07 am
by Support_Rick
The best solution is to determine your CutOff date ...

ie, Cutoff = Today - 30 days.

Then create a file list across your Archive folder structure generating a file list and only include files dated up to and including your Cutoff date.

Something like the following:
Code: Select all
<timestamp version="1.0">
	<format outputVariable="Cutoff" pattern="yyyy-MM-dd" dayOfMonth="-30" />
</timestamp>


<createFileList label="Get files to Delete" fileListVariable="FilesToDelete" numFilesFoundVariable="NoFilesToDelete" version="1.0">
	<fileset dir="\\MyArchive\MyFolder\MySubFolder" recursive="true">
		<dateFilter>
			<include to="${Cutoff}" />
		</dateFilter>
	</fileset>
</createFileList>
Now you have the Number of files that were found (NoFilesToDelete) that matches your Cutoff criteria, and you have a FileList (FilesToDelete) that you can do whatever you need with that identified list.

No ForEach loop is needed to delete those files unless you want to do each individually.

This can be called from a Scheduled Job to run once a week or once a month ... a Monitor isn't needed.