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条)

报告相同问题?

悬赏问题

  • ¥15 安装TIA PortalV15.1报错
  • ¥15 能把水桶搬到饮水机的机械设计
  • ¥15 Android Studio中如何把H5逻辑放在Assets 文件夹中以实现将h5代码打包为apk
  • ¥15 使用小程序wx.createWebAudioContext()开发节拍器
  • ¥15 关于#爬虫#的问题:请问HMDB代谢物爬虫的那个工具可以提供一下吗
  • ¥15 vue3+electron打包获取本地视频属性,文件夹里面有ffprobe.exe 文件还会报错这是什么原因呢?
  • ¥20 用51单片机控制急停。
  • ¥15 孟德尔随机化结果不一致
  • ¥15 在使用pyecharts时出现问题
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路