标签:io os sp for 文件 on bs cti ad
<?php
function bianli($dir){
$list=scandir($dir);
foreach($list as $v){ //遍历文件夹
$file_location=$dir."/".$v; //记录路径
if(is_dir($file_location)&&$v!="."&&$v!=".."){
echo $v." <br>";
echo ">>> $file_location ---<br>";
bianli($file_location);
}
}
}
bianli(‘d:\music‘);
?>
输出:
BGM
>>> d:\music\BGM ---
钢琴
>>> d:\music\钢琴 ---
例2: 遍历文件以及目录
$dirname = ‘d:\music‘;
function dirfor($dirname){
$dir = opendir($dirname);
readdir($dir);
readdir($dir);
while( $file = readdir($dir)){
$file = $dirname."\\".$file;
if( is_dir($file)){
echo "目录:".$file."<br>";
dirfor($file);
}else{
echo "   文件:".$file."<br>";
}
}
closedir($dir);
}
dirfor($dirname);
标签:io os sp for 文件 on bs cti ad
原文地址:http://www.cnblogs.com/Xavier13/p/4134039.html