zoukankan      html  css  js  c++  java
  • 删除某个时间段之前的文件

    /*
     * 删除文件夹下$n分钟前创建的文件
     * @param $dir 要处理的目录,物理路径,结尾不加
     * @param $n 过期时间,单位为分钟
     * @return void
     */
    function z_del_file_by_ctime($dir,$n){
        if(is_dir($dir)){
            if($dh=opendir($dir)){
                while (false !== ($file = readdir($dh))){
                    if($file!="." && $file!=".."){
                        $fullpath=$dir."/".$file;
                        if(!is_dir($fullpath)){ 
                            $filedate=filemtime($fullpath);
                            $minutes=round((time()-$filedate)/60);
                            if($minutes>$n)
                                unlink($fullpath); //删除文件
                        }
                    }
                }
            }
            closedir($dh);
        }
    }


    //下面是调用的代码
    //删除1天前的文件
    $dir = realpath('./Upload/export');
    z_del_file_by_ctime($dir, 24*60);
    %>

  • 相关阅读:
    CodeForces 58C Trees
    【转】二分匹配题集
    HDU2604 Queuing
    HDU1281 棋盘游戏
    HDU3360 National Treasures
    HDU2444 The Accomodation of Students
    HDU1498 50 years, 50 colors
    HDU1068 Girls and Boys
    【转】常用的latex宏包
    【转】网络流题集
  • 原文地址:https://www.cnblogs.com/jingxiaoniu/p/11497691.html
Copyright © 2011-2022 走看看