Jump to content

php search subdirectories and delete files


matt121400

Recommended Posts

Hello so somehow their are a ton of random phpfiles with numbers behind them then were created when replacing files that look like this test.php1323434435 and i am looking to delete them.  I have created this which works for deleting them when its in the same folder

 

<?php

$files = glob('test.php1*');

array_map('unlink', $files);

?>

 

my question is how do i get it to search all the subdirectories and do the same thing

 

 

Link to comment
Share on other sites

You can loop through the files and search for the folders with is_dir()

Of course, this depends on how many levels of folders we're talking about.

 

if ($handle = opendir('/path/to/files')) {
    while (false !== ($file = readdir($handle))) {
        if(is_dir($file)){
             // found a folder, do something with it
        }
    }
    closedir($handle);
}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.