Automatically delete old files in fetch

Hello, i want to do something that looked pretty simple to me at first look, but i’m stocked with this date thing! All I want to do is to run the script and it deletes all files and folders older than 15 days on my FTP site. Can somebody help me handling the way to use dates in my scripts.

Thank you

When it is local you can use:


do shell script "find /your_directory -mtime +15 -exec rm -f {} \\;"

What it does is finding all files with a mtime older than 15 days. Every file found in the result (with the exec option) will be removed.

it’s not local

Hi,

try this, the double repeat loop is necessary, because Fetch doesn’t return the proper file list with

set remoteItems to every remote item of transferWindow 

To avoid the common error to delete an item in a index number based list
the items are collected and then deleted in a reference based list


property theServerAddress : "myServer"
property theUserName : "myUserName"
property thePassword : "myPassword"
property theDirectory : "myDirectory"

set olderThan15days to (current date) - 15 * days
set itemsToDelete to {}
tell application "Fetch"
	set transferWindow to make new transfer window at beginning with properties ¬
		{hostname:theServerAddress, username:theUserName, password:thePassword, initial folder:theDirectory}
	with timeout of 600 seconds
		tell transferWindow
			repeat with i from 1 to (count remote items)
				set remoteItem to remote item i
				if modification date of remoteItem comes before olderThan15days then set end of itemsToDelete to remoteItem
			end repeat
			repeat with anItem in (get itemsToDelete)
				delete anItem
			end repeat
		end tell
	end timeout
end tell


Please test the script carefully. Deleting files on a remote server is irreversible

Thank you it works very well. I appreciate it. You have answers to everybody! you are probably not a prepress operator, like me :wink: