【问题标题】:How to get the file and directory list in a specific directory [duplicate]如何获取特定目录中的文件和目录列表[重复]
【发布时间】:2012-10-01 13:29:02
【问题描述】:

可能重复:
PHP list of specific files in a directory

我想列出我目录中的所有目录和文件。我该怎么做?下面是我的代码

if(opendir("user_files/".$uid."/")) {
var_dump(readdir("user_files/".$uid."/"));
}

【问题讨论】:

  • 使用glob()很简单
  • scandir 效果很好
  • scandir 正是这样做的。
  • @Baba thnx,请将此添加为您的答案,以便我接受它
  • @Ali Hassan ...当您获得目录列表时..您打算如何处理它们????仅添加如何列出目录将是重复的

标签: php directory readdir


【解决方案1】:

这是使用FilesystemIterator列出文件夹中文件的另一种方法

$dir = __DIR__;
$fi = new FilesystemIterator($dir, FilesystemIterator::SKIP_DOTS);
echo "<ul>";
printf("<b>Total Files :  %d</b>", iterator_count($fi));
foreach ( $fi as $file ) {
    printf("<li>%s : %d</li>", $file->getFileName(), $file->getSize());
}
echo "</ul>";

【讨论】:

    猜你喜欢
    • 2015-02-04
    • 2014-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-29
    • 2017-04-29
    • 2023-03-13
    相关资源
    最近更新 更多