delete folders in a directory that were created 4+ months ago

Does anyone know of a php script I can use to delete folders in a sub-directory that were created 4+ months ago?
Who is Participating?
PeterErhardAuthor Commented:
Thanks, where in that script do I control 4 months?
$dir = '/path/to/dir';
if ($handle = opendir($dir)) {
  /* This is the correct way to loop over the directory. */
  while (false !== ($file = readdir($handle))) {
    if ($file[0] == '.' || is_dir("$dir/$file")) {
       // ignore hidden files and directories
    if ((time() - filemtime($file)) > ($days *86400)) {

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.