• 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);*/
    

      

  • 相关阅读:
    Python + unittest + HTMLTestRunnerCN 生成接口自动化测试报告
    python 读写操作CSV文件
    with关键字
    Django常规命令大全
    科技阅读与写作资料
    Topics in Service Computing
    学习总结100515
    【论文收集】PQDT硕博库中的搜索结果service composition
    毕业开题结束感想
    excle操作备忘
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/8259885.html
Copyright © 2020-2023  润新知