Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3975638
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:42:32+00:00 2026-05-20T04:42:32+00:00

There is a directory /home/example/public_html/users/files/ . Within the directory there are subdirectories with random

  • 0

There is a directory /home/example/public_html/users/files/. Within the directory there are subdirectories with random names like 2378232828923_1298295497.

How do I completely delete the subdirectories which have creation date > 1 month?

There is a good script that I use to delete files, but it don’t work with dirs:

$seconds_old = 2629743; //1 month old
$directory = "/home/example/public_html/users/files/";

            if( !$dirhandle = @opendir($directory) )
                        return;

             while( false !== ($filename = readdir($dirhandle)) ) {
                     if( $filename != "." && $filename != ".." ) {
                                $filename = $directory. "/". $filename;

                             if( @filectime($filename) < (time()-$seconds_old) )
                                      @unlink($filename); //rmdir maybe?
                     }
             }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:42:33+00:00Added an answer on May 20, 2026 at 4:42 am

    you need a recursive function for this.

    function remove_dir($dir)
    {
        chdir($dir);
        if( !$dirhandle = @opendir('.') )
            return;
    
        while( false !== ($filename = readdir($dirhandle)) ) {
            if( $filename == "." || $filename = ".." )
                continue;
    
            if( @filectime($filename) < (time()-$seconds_old) ) {
                if (is_dir($filename)
                    remove_dir($filename);
                else 
                    @unlink($filename);
            }
        }
        chdir("..");
        rmdir($dir);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python project with this directory structure and these files: /home/project_root |---__init__.py
I wanted to rename the files in a directory.There are 52 folders in the
There's a directory with a few text files. How do I count the frequency
Is there a way to specify the root directory at runtime within a program's
I have a lighttpd server with website placed in /home/httpd/example.com/httpdocs and there I have
Hi I'm new to putting up websites. I have a document root: home/user/public_html/www.example.com/public where
I have ruby and the gems installed within /home/insane-36/.rvm directory. I installed the passenger
Let's say there's following directory structure: root | +--projects | | | +-test |
Jboss 4.2.0A Is there a /server directory that I need to change or something?
Is there any way to find the parent directory of a path using NSFileManager

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.