【发布时间】:2011-08-19 14:28:13
【问题描述】:
我使用 shell find 命令列出目录中的所有文件。它工作正常。我想列出在指定日期之后修改的所有文件,我使用了这个命令
$command='touch -date "2010-01-18" /home;find.-newer /home ';
$Getfile = exec($command,$ret,$output);
但它不起作用。提前致谢
【问题讨论】:
-
什么不起作用,shell 命令或
exec()调用?你得到了什么?一个错误,没有输出等等...... -
我敢打赌,如果你在 shell 中使用 that find 命令,它也不会起作用。
-
-newer 参数需要一个指向文件的指针作为参考,哪些文件应该显示为较新的文件。参见手册页
File was modified more recently than file. If file is a symbolic link and the -H option or the -L option is in effect, the modification time of the file it points to is always used.所以你必须触摸一个文件而不是一个目录,并使用这个文件作为参考,或者你只需要触摸并使用-cmin <minutes since last change>,因为你使用 php 很遗憾计算特定的分钟数日期。 -
@DaveRandom 我正在获取此文件夹中的所有文件
-
您可以对此进行更精细的控制,如果/当您将脚本移植到 Windows 或其他操作系统时,不会冒破坏脚本的风险,并且如果您使用组合,则不必解析另一个命令的输出的
opendir()和filemtime()来完成这项工作......