php 扫描文件夹 列出文件

<meta http-equiv=content-type content="text/html; charset=UTF-8">
<?php
 
function u_g($path){
	return  iconv("UTF-8", "GB2312", $path);
}
function g_u($path){
	return  iconv("GB2312", "UTF-8", $path);
}

function my_scandir($rootPath){
	$targetDeck = u_g($rootPath);
	if(is_dir($targetDeck)){
		scanIt($targetDeck); 
	}else{
		echo g_u($rootPath)."  文件夹不存在";
	}
}

function scanIt($targetDeck){
	if ($handle = @opendir($targetDeck)) { 
		while (false !== ($file = @readdir($handle))) {
			if($file=='.' || $file=='..'){
				continue;
			} 
			$nextDeck = $targetDeck."".$file;
			if(is_dir($nextDeck)){ 
				scanIt($nextDeck); 
				echo "dir: ".g_u($nextDeck)."<br/>";
			}else{
				if($file !=="Thumbs.db"){
					echo "file: ".g_u($nextDeck)."<br/>";
				}
			}
		}
		@closedir($handle);
	}
	return;
}

my_scandir( $_SERVER['DOCUMENT_ROOT']."/新建文件夹/");

?>

你可能感兴趣的:(php 扫描文件夹 列出文件)