You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

scandir( $path) returns the searched result in array.

$result = scandir(directory, order, context)

  • it returns false on failure.


<?php

$r = scandir("/etc/");
print_r( $r);

?>


Below is another example to find files in regexp.

function findfiles( $path, $regexp)
{
        $r = scandir( $path);
        if ($r==true)
        {
                $i=count($r)-1;
                while($i>=0)
                {
                        if (!preg_match('/' . $regexp . '/', $r[$i])) unset($r[$i]);
                        $i--;
                }
                return $r;
        }
}

$r = findfiles( "/repostirory", "mysql");
print_r($r);
  • No labels