Page 1 of 1

Move files older than X amount of days

Posted: Wed May 21, 2014 2:49 am
by Cnile31
Greetings,

We have just started implementing and using GoAnywhere Director within our company. Basic file moving tasks are already in use. For example, move all files in folder X to folder Y. Unfortunately we don't yet have the knowlegde of Director to perform slightly more advanced tasks.

What we are now trying to do is move files from folder X to folder Y when these files are older than an X amount of days. Does anyone perhpaps know how we can accomplish this?

Any help would be very much appreciated.

Thanks in advance.

Re: Move files older than X amount of days

Posted: Wed May 21, 2014 10:39 am
by Jonathan
Hi,

You can try the project below, It will exclude all files in folderX from X days ago to today and move everything else to folderY. You can set the amount of days by changing the X variable at the bottom of the project.
Code: Select all
<project name="MoveFiles" mainModule="Main" version="2.0">

	<module name="Main">

		<timestamp version="1.0">
			<format outputVariable="date" pattern="ddMMyyyy" dayOfMonth="-${x}" />
		</timestamp>


		<move destDir="FolderY" version="1.0">
			<fileset dir="FolderX">
				<dateFilter>
					<exclude from="${date}" to="${system.currentDate}" />
				</dateFilter>
			</fileset>
		</move>

	</module>

	<variable name="x" value="30" description="Files older than this will be moved" />
</project>
There is also a project by Rick that you can find here: http://www.goanywheremft.com/forum/post462.html#p462 which will clean up directories but could be adapted for your needs.

Re: Move files older than X amount of days

Posted: Thu May 22, 2014 1:06 am
by Cnile31
Thanks for the quick reply Jonathan! I'll try it out asap.

Re: Move files older than X amount of days

Posted: Thu May 22, 2014 2:42 am
by Cnile31
I have tried to run the project with the code that you provided. Unfortunately it resulted in the following error:

[8003 - move] Invalid value '22042014' for attribute 'from' in element 'exclude'

Any idea what could cause this? I have tried adjusting the date/time formats within the xml and the systems on which the file shares are located (don't know if this is even the issue). Unfortunately without results.

Re: Move files older than X amount of days

Posted: Thu May 22, 2014 8:43 am
by Support_Rick
If you click on the prompt word "From Date", you will see the following:

From Date
Specify a Start Date. The date must be entered in yyyy-MM-dd format. If a start time other than midnight is desired, then the format is yyyy-MM-dd HH:mm:ss. Leaving this value blank will match all files that are modified before the specified To Date.


Format your dates (to and from) to match this and you should be good to go.

Re: Move files older than X amount of days

Posted: Fri May 23, 2014 3:38 am
by Cnile31
Thanks for the help Rick and Jonathan. Thanks to you I was able to succesfully create a working project for this matter. My final code for this project is as follows:
Code: Select all
<project name="Move files older than X amount of days" mainModule="Main" version="2.0">

	<module name="Main" onError="abort">

		<timestamp version="1.0">
			<format outputVariable="date" pattern="yyyy-MM-dd" dayOfMonth="-${x}" />
		</timestamp>


		<timestamp version="1.0">
			<format outputVariable="system.currentDate" />
		</timestamp>


		<copy destDir="Destination" preserveDate="true" processedSourceFilesVariable="processed" version="1.0">
			<fileset dir="Source" recursive="false">
				<dateFilter>
					<exclude from="${date}" to="${system.currentDate}" />
				</dateFilter>
			</fileset>
		</copy>


		<delete inputFilesVariable="${processed}" version="1.0" />

	</module>

	<variable name="x" value="30" description="Files older than this will be moved" />
</project>
I had to use a seperate timestamp to set the "system.currentDate" variable because otherwise the variable would receive the same value as the "date" variable. Because the move takes place between Windows shares in seperate domains, the move command was replaced with a copy and delete, just like in my other topic:
(http://www.goanywheremft.com/forum/dire ... -t534.html

I hope my little piece of code will help others who are also new to GoAnywhere.

Re: Move files older than X amount of days

Posted: Fri May 23, 2014 8:20 am
by Support_Rick
Glad you go this going!! Congrats ...

Here's a couple tweaks that will make things much smoother for you...

Instead of this:
Code: Select all
<timestamp version="1.0">
	<format outputVariable="system.currentDate" />
</timestamp>
You can use a System Function:
Code: Select all
${ CurrentDate() }

Thus, your DateFilter would look something like this:
Code: Select all
<dateFilter>
	<exclude from="${date}" to="${ CurrrentDate() }" />
</dateFilter>
The Default Value for that function is the ISO date format (yyyy-MM-dd), which is what you need for this Project.

Take a look at these Forum Posts for further information:

How to Generate the Current Date

Using Variables in GoAnywhere Director Project