计算目录php中的多少个文件 [英] Count how many files in directory php
本文介绍了计算目录php中的多少个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做一个稍微新的项目。
< div id =我想知道如何让它计算在某个目录中有多少文件。 header>
<?php
$ dir = opendir('uploads /'); #这是它将从
$ i = 0计算的目录; #整数从0开始计数
#false不等于目录
while(false!==($ file = readdir($ dir))){
if(!in_array($ file,array('。','..')和!is_dir($ file))$ i ++;
}
echo ;#打印目录中有多少项目
?>
< / div>
b $ b
这是我到目前为止(从搜索),但它没有正确显示?我添加了一些笔记,所以随意删除他们,只是因此我可以理解它,可以。
如果您需要一些更多的信息或感觉,如果我没有描述这足够,请随时说出这样。
$ fi = new FilesystemIterator(__ DIR__,FilesystemIterator :: SKIP_DOTS);
printf(有%d个文件,iterator_count($ fi));
I'm working on a slightly new project. I wanted to know how to make it so it counts how many files are in a certain directory.
<div id="header"> <?php $dir = opendir('uploads/'); # This is the directory it will count from $i = 0; # Integer starts at 0 before counting # While false is not equal to the filedirectory while (false !== ($file = readdir($dir))) { if (!in_array($file, array('.', '..') and !is_dir($file)) $i++; } echo "There were $i files"; # Prints out how many were in the directory ?> </div>
This is what I have so far (from searching). However it is not appearing properly? I have added a few notes so feel free to remove them, they are just so I can understand it as best as I can.
If you require some more information or feel as if I haven't described this enough please feel free to state so.
解决方案You can simply do the following :
$fi = new FilesystemIterator(__DIR__, FilesystemIterator::SKIP_DOTS); printf("There were %d Files", iterator_count($fi));
这篇关于计算目录php中的多少个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文