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

 

 

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);
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.