doucong4535 2015-03-17 13:09
浏览 129
已采纳

查找在当前日期创建的文件夹和子文件夹中的文件

I am trying to find files that were created today. I found most of my answer in other posts, but can't quite get it right. The code below echos all of the files instead of just those that were created today. Any suggestions? Thanks.

$di = new RecursiveDirectoryIterator('/documents/listings');
foreach (new RecursiveIteratorIterator($di) as $filename => $file) 
{

    if (date ("m-d-Y", filemtime($file)) == date("m-d-Y")) 

    { echo $filename . '<br/>'; }

}
  • 写回答

3条回答 默认 最新

  • duanjiao2978 2015-03-18 05:42
    关注

    First of all, about function filemtime, it returns: file modification time.
    But also exists function filectime, it returns: inode change time of file.
    As i found filectime more better for your question, but it really returns files not only created today but also edited today.

    My code:

    <?php
    
    $path = dirname(__FILE__);
    
    $objects = new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator($path),
        RecursiveIteratorIterator::SELF_FIRST
    );
    foreach ($objects as $file => $object) {
        $basename = basename($file);
        if ($basename == '.' or $basename == '..') {
            continue;
        }
        if (is_dir($file)) {
            continue;
        }
        if (date('Y-m-d') === date('Y-m-d', filectime($file))) {
            echo $file . PHP_EOL;
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?