Move files older than X amount of days

Post any question you may have in regards to GoAnywhere Director and let our talented support staff and other users assist you.
7 posts Page 1 of 1

Cnile31

Posts: 7
Joined: Tue May 20, 2014 6:20 am

Post by Cnile31 » Wed May 21, 2014 2:49 am
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.

Jonathan

Posts: 18
Joined: Wed Jan 02, 2013 5:27 am
Location: Mapledurham, UK

Post by Jonathan » Wed May 21, 2014 10:39 am
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.

Cnile31

Posts: 7
Joined: Tue May 20, 2014 6:20 am

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

Cnile31

Posts: 7
Joined: Tue May 20, 2014 6:20 am

Post by Cnile31 » Thu May 22, 2014 2:42 am
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.

Support_Rick

Support Specialist
Posts: 592
Joined: Tue Jul 17, 2012 2:12 pm
Location: Phoenix, AZ

Post by Support_Rick » Thu May 22, 2014 8:43 am
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.
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696

Cnile31

Posts: 7
Joined: Tue May 20, 2014 6:20 am

Post by Cnile31 » Fri May 23, 2014 3:38 am
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.

Support_Rick

Support Specialist
Posts: 592
Joined: Tue Jul 17, 2012 2:12 pm
Location: Phoenix, AZ

Post by Support_Rick » Fri May 23, 2014 8:20 am
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
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
7 posts Page 1 of 1