HOME > > > > >

search()

File_Find::search()

ディレクトリ内で指定したパターンにマッチするものを検索します。指定ディレクトリ以下の指定パターンにマッチしたディレクトリ、ファイルを返す。

&File_Find::search(string $pattern, string $dirpath [, string $pattern_type = 'php' [, bool $fullpath = true [, string $match = 'files']]])

引数

$pattern
ディレクトリを検索する際のパターンを含む文字列を指定します
$dirpath
検索するディレクトリパスを含む文字列を指定します
$pattern_type
使用するパターンマッチング関数を含む文字列を指定します ('php'、'perl' もしくは 'shell' のいずれかが指定可能です)。
$pattern のフォーマットは、 $pattern_type の値に依存します。 詳細な情報は、 検索方法 を参照ください。
$fullpath
文字列の検索をフルパスに対して行うのか、 ファイル名に対してのみ行うのかを指定します。
$match
'files'、'directories' あるいは 'both' のいずれかで、返すリストの形式を指定します。

戻り値

array
全てのファイル名を含む配列

動作サンプル

PHP

  1. <?php
  2. require_once('File/Find.php');
  3.  
  4. echo ".phpを含むファイルを取得<br />";
  5. $fileinfo = &File_Find::search('/.php$/', LIB_SAMPLE . 'file_find/', 'perl');
  6. foreach ($fileinfo as $value) {
  7.     echo str_replace($_SERVER['DOCUMENT_ROOT'], 'http://www.kantenna.com', $value) . "<br />";
  8. }
  9. ?>
実行結果
.phpを含むファイルを取得
http://www.kantenna.com/sample/file_find/lv2/lv2file_find.php
http://www.kantenna.com/sample/file_find/lv2/lv3/test1.php
http://www.kantenna.com/sample/file_find/lv2/lv3/test2.php
http://www.kantenna.com/sample/file_find/lv2/lv3/test3.php
http://www.kantenna.com/sample/file_find/lv2/test.php
http://www.kantenna.com/sample/file_find/lv2/test1.php
http://www.kantenna.com/sample/file_find/lv2/test2.php
http://www.kantenna.com/sample/file_find/lv2/test3.php
http://www.kantenna.com/sample/file_find/test.php
http://www.kantenna.com/sample/file_find/test1.php
http://www.kantenna.com/sample/file_find/test2.php
http://www.kantenna.com/sample/file_find/test3.php