Created
July 21, 2013 22:27
-
-
Save Xeroday/6050249 to your computer and use it in GitHub Desktop.
Deletes .tar.gz files older than 7 days.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$files = glob("*.tar.gz"); | |
foreach($files as $file) { | |
if(is_file($file) | |
&& time() - filemtime($file) >= 7*24*60*60) { // 7 days | |
unlink($file); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Tyler, I just noticed you probably got a little confused about the time script, for me, it looks like 7 days, multiplied for 24 hours, then for 60 minutes and then for 60 seconds, so you get the total time in seconds;
If you multiply anything by zero it's zero, so it'll delete anything higher than zero. You were probably looking for something like: 28,4 hours * 60 minutes * 60 seconds, so you'll get arround a day, four hours and some minutes converted in seconds.
If you're still in doubt, that's your answer