Skip to content

Instantly share code, notes, and snippets.

@tohokuaiki
Last active November 16, 2016 03:07
Show Gist options
  • Save tohokuaiki/e748082b880ed72907b67cce28c89210 to your computer and use it in GitHub Desktop.
Save tohokuaiki/e748082b880ed72907b67cce28c89210 to your computer and use it in GitHub Desktop.
ディレクトリ以下の全てのファイルを列挙
<?php
function getFileList($dir, $list=array('dir'=> array(), 'file' => array()))
{
if (is_dir($dir) == false) {
return $list;
}
$dh = opendir($dir);
if ($dh) {
while (($file = readdir($dh)) !== false) {
if ($file == '.' || $file == '..'){
continue;
}
else if (is_dir("$dir/$file")) {
$list = getFileList("$dir/$file", $list);
$list['dir'][] = "$dir/$file";
}
else {
$list['file'][] = "$dir/$file";
}
}
}
closedir($dh);
return $list;
}
@tohokuaiki
Copy link
Author

tohokuaiki commented Nov 16, 2016

PHPでディレクトリ以下のファイル一覧を取得

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment