Skip to content

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.
  • Cnile31 Offline
  • Posts: 7
  • Joined: Tue May 20, 2014 6:20 am

Move files older than X amount of days

Post 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.
  • Jonathan Offline
  • Posts: 18
  • Joined: Wed Jan 02, 2013 5:27 am
  • Location: Mapledurham, UK
  • Contact:

Re: Move files older than X amount of days

Post 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.
  • Cnile31 Offline
  • Posts: 7
  • Joined: Tue May 20, 2014 6:20 am

Re: Move files older than X amount of days

Post by Cnile31 »

Thanks for the quick reply Jonathan! I'll try it out asap.
  • Cnile31 Offline
  • Posts: 7
  • Joined: Tue May 20, 2014 6:20 am

Re: Move files older than X amount of days

Post 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.
  • Support_Rick Offline
  • Support Specialist
  • Posts: 590
  • Joined: Tue Jul 17, 2012 2:12 pm
  • Location: Phoenix, AZ
  • Contact:

Re: Move files older than X amount of days

Post 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.
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
  • Cnile31 Offline
  • Posts: 7
  • Joined: Tue May 20, 2014 6:20 am

Re: Move files older than X amount of days

Post 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.
  • Support_Rick Offline
  • Support Specialist
  • Posts: 590
  • Joined: Tue Jul 17, 2012 2:12 pm
  • Location: Phoenix, AZ
  • Contact:

Re: Move files older than X amount of days

Post 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
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
Post Reply