//$dir-文件地址,$files-存储返回数组,$type-查找文件类型组
public function read_dir($dir,&$files,$type) {
if(!is_dir($dir)) {
echo "no dir";
return false;
}
$handle = opendir($dir);
if ($handle) {
while ( ($f1 = readdir($handle)) !== false ) {
$temp = $dir.DIRECTORY_SEPARATOR.$f1;
if ( $f1!='.' && $f1!='..' ) {
if ( is_dir($temp) ) {
read_dir($temp,$files,$type);
}else{
$files[]=$temp;
}
}
}
}
 /*查看并返回要删除文件*/
public function showphp() {
$arr=array();
$del_arr=array();//要删除文件
$url = $_SERVER['DOCUMENT_ROOT']."/downlist/";
$this->read_dir($url,$arr,["html"]);
foreach($arr as $file)
{
$file_date=date("Y-m-d H:i:s",filemtime($file));
$del_date="2019-04-15";//指定时间
if ($file_date<$del_date) {
echo $file_date . " : " . $file . "<br>";
$del_arr[]=$file;
}
}
return $del_arr;
}
//执行删除操作
public function del(){
$del_arr=$this->showphp();
foreach($del_arr as $file)
{
if (!unlink($file)) {
echo("Error deleting $file");
} else {
echo("Deleted $file <br>");
}
}
}

php根据修改时间删除指定目录下文件的更多相关文章

  1. [No000073]C#直接删除指定目录下的所有文件及文件夹(保留目录)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  2. Python批量删除指定目录下的指定类型的文件

    Python作为一种脚本语言.其很适合文件级的各种操作.以下的代码能够批量删除指定目录下的所有特定类型(CSV类型)的文件. import sys, csv , operator import os ...

  3. Java基础---Java---IO流-----File 类、递归、删除一个带内容的目录、列出指定目录下文件夹、FilenameFilte

    File 类 用来将文件或者文件夹封装成对象 方便对文件与文件夹进行操作. File对象可以作为参数传递给流的构造函数 流只用操作数据,而封装数据的文件只能用File类 File类常见方法: 1.创建 ...

  4. linux --> 删除指定目录下所有文件

    删除指定目录下所有文件 代码样例: ///////////////////////////////////////////////////// //Name: DeleteFile //Purpose ...

  5. C# 删除指定目录下的所有文件及文件夹

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...

  6. C#直接删除指定目录下的所有文件及文件夹(保留目录)

    #region 直接删除指定目录下的所有文件及文件夹(保留目录) /// <summary> /// 直接删除指定目录下的所有文件及文件夹(保留目录) /// </summary&g ...

  7. IO流-获取指定目录下文件夹和文件对象【File类】

    一.运用File类实现获取指定目录下文件夹和文件对象 1.File类 2.方法: 获取文件绝对路径 :getAbsolutePath 案例: import java.io.File; /** * 获取 ...

  8. python 实现统计ftp服务器指定目录下文件夹数目、文件数目及所有文件大小

    本次主要为满足应用方核对上传到ftp服务器的文件是否缺漏. 主要要求:指定目录下,文件夹数目/文件数目/所有文件大小,类似Windows如下功能: 模块介绍: from ftplib import F ...

  9. php删除指定目录所有文件

    <?php /** * 删除指定文件目录下的所有文件 * @param str $dir 指定文件路径: 如:K:/wamp/www/test * return boole *--------- ...

随机推荐

  1. python 日志滚动 分文件

    import logging from logging.handlers import RotatingFileHandler import datetime import os def main() ...

  2. Maximum Average Subarray II LT644

    Given an array consisting of n integers, find the contiguous subarray whose length is greater than o ...

  3. oracle 62进制序列号

    create or replace function GetSerial62(v_lpad number default 0) return varchar2 IS v_tmp number(38,0 ...

  4. 如何从jks文件中导出公私钥

    1.从JKS转换到PKCS12 #keytool -importkeystore -srckeystore <MY_KEYSTORE.jks> -destkeystore <MY_F ...

  5. 蛋白序列GO号注释及问题

    #===============================      版本1  ===============================================InterProSc ...

  6. Anaconda 3中配置OpenCV

    平台:win10 x64+Anaconda 3(64-bit)+opencv_python-3.4.5+contrib-cp37-cp37m-win_amd64 一.OpenCV下载 Python环境 ...

  7. python学习之ansible api

    Python API 2.0 从2.0的事情开始更复杂一些,但是你会得到更多离散和可读的类: #!/usr/bin/env python import json from collections im ...

  8. oracle listagg within group

    案例: 查看,每个人身上的标签. 1)表数据 2)SQL select name,listag(tag,',') within group(order by tag) tags from table_ ...

  9. centos下利用yum安装LAMP(Linux+Apache+MySQL+PHP)及配置

    先说下我的实践配置,centos6.5(64位),联网 安装前准备:关闭防火墙 service iptables stop 安装MySQL 打开终端,root用户 1 yum install mysq ...

  10. 将驼峰转化为下化线(将型如AbcDef转化为abc_def)

    strtolower(preg_replace('/((?<=[a-z])(?=[A-Z]))/', '_', 'AbcDef'))