Skip to content

Instantly share code, notes, and snippets.

@ogaty
Created September 8, 2018 04:10
Show Gist options
  • Save ogaty/13c9307325a30d44808ae16b8d97f07c to your computer and use it in GitHub Desktop.
Save ogaty/13c9307325a30d44808ae16b8d97f07c to your computer and use it in GitHub Desktop.
特定ディレクトリ配下をrecursiveで探索 php directory
<?php
$path = 'node_modules';
function getFileList($dir) {
$iterator = new RecursiveDirectoryIterator($dir);
$iterator = new RecursiveIteratorIterator($iterator);
$list = array();
foreach ($iterator as $fileinfo) { // $fileinfoはSplFiIeInfoオブジェクト
if ($fileinfo->isFile() && preg_match('/\.js$/', $fileinfo->getPathname())) {
$list[] = $fileinfo->getPathname();
}
}
return $list;
}
var_dump(getFileList($path));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment