標籤:
<?php
/**
* 遍曆檔案夾和檔案列
* @author lizhiming
* @date 2016/06/30
*/
define(‘DS‘, DIRECTORY_SEPARATOR);
class File
{
//返回數組
private $DirArray = array();
private $FileArray = array();
private $DirFileArray = array();
private $Handle, $Dir, $File;
//擷取目錄列表
public static function getDir(& $Dir)
{
if (is_dir($Dir)) {
if (false != ($Handle = opendir($Dir))) {
while (false != ($File = readdir($Handle))) {
if ($File != ‘.‘ && $File != ‘..‘ && !strpos($File, ‘.‘) && is_dir($File)) {
$DirArray[] = $File;
}
}
closedir($Handle);
}
} else {
$DirArray[] = ‘[Path]:\‘‘ . $Dir . ‘\‘ is not a dir or not found!‘;
}
return $DirArray;
}
//擷取檔案清單
public static function getFile(& $Dir)
{
if (is_dir($Dir)) {
if (false != ($Handle = opendir($Dir))) {
while (false != ($File = readdir($Handle))) {
if (($File != ‘.‘ && $File != ‘..‘ && strpos($File, ‘.‘)) || is_file($File)) {
$FileArray[] = $File;
}
}
closedir($Handle);
}
} else {
$FileArray[] = ‘[Path]:\‘‘ . $Dir . ‘\‘ is not a dir or not found!‘;
}
return $FileArray;
}
//擷取目錄/檔案清單
public static function getDirFile(& $Dir)
{
if (is_dir($Dir)) {
$DirFileArray[‘DirList‘] = self::getDir($Dir);
if ($DirFileArray) {
foreach ($DirFileArray[‘DirList‘] as $Handle) {
$File = $Dir . DS . $Handle;
$DirFileArray[‘FileList‘][$Handle] = self::getFile($File);
}
}
} else {
$DirFileArray[] = ‘[Path]:\‘‘ . $Dir . ‘\‘ is not a dir or not found!‘;
}
return $DirFileArray;
}
}
php 遍曆目錄下的所以檔案和檔案夾