• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 338
  • Last Modified:

PHP get all files in DIR

My question stem form an old one I asked a while back.
OLD Question

In the code below I am trying to change the first line  Into code that will get all the files in a DIR
and run the rename script on each of them.

Exact file names are unknown.

Any help is appreciated.
Thank you

Selvol
<?php
$str = file_get_contents("a.php");
        preg_match('%<meta name=\"keywords\" content=\"([^"]*)"%i',$str,$matchArray);
        $namesArray = explode(",",$matchArray[1]);
        $file = fopen($namesArray[0].$namesArray[1].$namesArray[3].".txt","w+");
        fwrite($file,$str);
        fclose($file);
?>

Open in new window

0
selvol
Asked:
selvol
1 Solution
 
gr8gonzoConsultantCommented:
Use the glob function:

<?php

$filesInDirectory = glob("*");
foreach($filesInDirectory as $filename)
{
   echo $filename;
   // all your per-file logic goes here
}

?>

glob("*.php") returns only files ending in .php
glob("a*") returns all files starting with "a"
0
 
selvolAuthor Commented:
Thank you for the help.  

Selvol
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now