I have a directory that contains multiple subdirectories. In each subdirectory there are a few files. Some subdirectories have index.php file in them and some don't.
I need to write a script that will check all subdirectories within main directory for that index.php file. If it is present, ignore this subdirectory and go on to the next one. If it is not present, create it.
This is how I insert the file at the moment but only in a single directory:
// insert php redirect into directory
$redirectFile = 'mySubDirectory/index.php';
if (!file_exists($redirectFile)) {
$contents = '<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.domain.com" );
?> ';
file_put_contents($redirectFile, $contents);
}
I'd like to automate the process by letting the script run and check recursively all subdirectories (about 3.5K in count).
Not sure how to do that. Perhaps I can scan all subdirectories and store their names in an array and then do the loop? Not sure if that's the best solution.