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

Compare with Current View Page History

« Previous Version 7 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.

// Programmed by Chun Kang - 2020-03-27
function findfiles( $path, $regexp="", $order=0)
{
	$r = scandir( $path, $order); // $order: 0->ascending / 1->descending
	if ($r==false) $ret=$r;
	else if ($regexp!="")
	{
		$ret=array();
		$i=count($r)-1;
		for($i=0; $i<count($r); $i++)
		{
			if (preg_match('/' . $regexp . '/', $r[$i])) $ret[]=$r[$i];
		}
	}
	return $ret;
}

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