文件创建时间 [英] File creation time

查看:65
本文介绍了文件创建时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过文件创建对目录进行排序,最新的版本是PHP 5.2?

How do I sort a directory by file creation, latest first in PHP 5.2?

我在Windows 2000上.

I am on Windows 2000.

推荐答案

在Windows上,CTime是创建时间,请使用以下命令:

On windows the CTime is the creation time, use the following:

<?php
$files = array();

foreach (new DirectoryIterator('/path') as $fileInfo) {    
    $files[$fileInfo->getFileName()] = $fileInfo->getCTime();
}

arsort($files);

在此之后,$ files将包含一个文件名数组作为键,而ctime作为值.我之所以选择这种向后表示,是因为可能存在相同的ctime,这会导致$ files中的条目被覆盖.

After this $files will contain an array of your filenames as the keys and the ctime as the values. I chose this backwards representation due to the possibility of identical ctimes, which would cause an entry in $files to be overwritten.

使用CTime作为OP的更新答案阐明了他正在使用Windows.

Updated answer to use CTime as the OP clarified he's using Windows.

这篇关于文件创建时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆