-1

我想编写一个 PHP 脚本,它会告诉我今天创建了多少个文件夹(没有修改一个!!)。

前任。假设如果给出了路径(如 c:\Data ),那么我的脚本必须不断检查给出的路径是否是任何文件夹的新条目。我用过http://php.net/manual/en/function.date-diff.php。但也得到修改文件夹的结果。

4

2 回答 2

1

来自@Alin Purcaru 的引用

使用文件时间。对于 Windows,它将返回创建时间,对于 Unix,更改时间是您可以获得的最佳时间,因为在 Unix 上没有创建时间(在大多数文件系统中)。

使用参考文件来比较文件年龄允许您使用数据库检测新文件。

// Path to the reference file. 
// All files newer than this will be treated as new
$referenceFile="c:\Data\ref";
// Location to search for new folders
$dirsLocation="c:\Data\*";

// Get modification date of reference file
if (file_exists($referenceFile))
  $referenceTime = fileatime($referenceFile);
else 
  $referenceTime = 0;

// Compare each directory with the reference file
foreach(glob($dirsLocation, GLOB_ONLYDIR) as $dir) {
  if (filectime($dir) > $referenceTime)
    echo $dir . " is new!";
}

// Update modification date of the reference file
touch($referenceFile);

另一种解决方案可能是使用数据库。任何不在数据库中的文件夹都是新的。这确保不会捕获修改过的文件夹。

于 2013-06-27T13:37:58.023 回答
0

您可能想尝试每隔一分钟使用 cron 启动您的脚本,并检查目录列表之间的差异(我的意思是从之前和当前),而不是日期。这不是一个完美的解决方案,但它会起作用。

检查目录数组:

$dirs = array_filter(glob('*'), 'is_dir');

稍后将它们与array_diff进行比较

于 2013-06-27T13:25:36.247 回答