005PHP文件处理——目录操作,统计大小 filesize unlink

<?php
/* 目录操作,统计大小 filesize  unlink
 * */

$dir = dir(".");
while (($file = $dir->read()) !== FALSE) {
    echo $file . "<br/>";
}
$dir->close();

//filesize()得到文件大小,返回单位为字节:
//echo filesize('a.txt')/1024;

//unlink() 删除文件:
//6秒之后删除文件a.php
/*sleep(6);
unlink('a.php');*/

//删除60目录下的所有的doc后缀文件:
//array_map(unlink,glob('60\*.doc'));

//删除60目录下的所有文件:
//array_map(unlink,glob('60\*.*'));

//统计目录中所有文件的大小和:

/*function dirSize($dirname)
{
    $count = 0;
    $dir = opendir($dirname);
    while (($file = readdir($dir)) !== FALSE) {
        $filename = $dirname . '\\' . $file;
        if ($file != '.' && $file != '..') {
            if (is_dir($file)){
                $count += dirSize($file);
            }else {
                $count += filesize($filename);
            }
        }
    }
    return $count;
}

echo dirSize('.') / pow(1024, 2);*/


//通过glob统计文件夹大小:
/*function dirSize_glob($dirname){
    $count=0;
    $dirname=glob("{$dirname}\*");
    foreach ($dirname as $v){
        if (is_dir($v)){
            $count+=dirSize_glob($v);
        }else{
            $count+=filesize($v);
        }
    }
    return $count;
}
echo dirSize_glob('.')/pow(1024,2);*/

//通过scandir统计目录总的大小:
/*function dirSize_scandir($dirname)
{
    $count = 0;
    $dirArr = scandir($dirname);
    foreach ($dirArr as $v){
        $fileName=$dirname."\\".$v;
        if ($v!='.'&&$v!=".."){
            if (is_dir($fileName)){
                $count+=dirSize_scandir($fileName);
            }else{
                $count+=filesize($fileName);
            }
        }
    }
    return $count;
}

echo dirSize_scandir('.') / pow(1024, 2);*/

  

posted @ 2018-01-10 17:38  生如逆旅,一苇以航  阅读(146)  评论(0编辑  收藏  举报