0

I need to create a routine that does the following tasks:

  • Delete files in a specific folder that are more than 15 days of creation.
  • Clear the cache folder daily
  • Clean other specific folders also daily

I use easycron.com, therefore it's necessary that this routine is within the cron.php.

1
  • 1
    Just an idea, as your goal(s) are not defined in further detail: You do not necessarily need to write a Magento-Cronjob for this. You can achieve this with basic OS-commands (at least for Unix as I can speak) and execute them locally via cron on your webshop server. Commented Apr 13, 2015 at 21:28

1 Answer 1

2

Since you want to work with clearing folders based on a date I would suggest that this will be easier by using standard Unix commands, assuming that your system is unix based.

If you look into the function find you will see that you can specify the time of creation by the option mtime.

An example of this is:

find /path/to/files* -mtime +5

This will find files that are older than 5 days. You can then use the option exec to call a command on the files found. In your case you could call rm and that would remove the files. An example of this would be:

find /path/to/files* -mtime +5 -exec rm {} \;

NOTE: be careful before you run anything that can remove files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.