当前位置:网站首页>PHP 统计指定文件夹下文件的数量
PHP 统计指定文件夹下文件的数量
2022-04-23 04:46:00 【yizecellophp】
<?php
//给我一个文件夹,返回该文件夹下所有的文件数量
function ShuLiang($url)//造一个方法,给一个参数
{
$sl=0;//造一个变量,让他默认值为0;
$arr = glob($url);//把该路径下所有的文件存到一个数组里面;
foreach ($arr as $v)//循环便利一下,吧数组$arr赋给$v;
{
if(is_file($v))//先用个if判断一下这个文件夹下的文件是不是文件,有可能是文件夹;
{
$sl++;//如果是文件,数量加一;
}
else
{
$sl+=ShuLiang($v."/*");//如果是文件夹,那么再调用函数本身获取此文件夹下文件的数量,这种方法称为递归;
}
}
return $sl;//当这个方法走完后,返回一个值$sl,这个值就是该路径下所有的文件数量;
}
echo ShuLiang("upload/*");//用这个方法查一下该路径下所有的文件数量 根目录下的文件名即可;
?>
版权声明
本文为[yizecellophp]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Celloda/article/details/124302358
边栏推荐
- Unity3d practical skills - theoretical knowledge base (I)
- What is the thirty-six plan
- Error occurs when thymeleaf th: value is null
- 補:注解(Annotation)
- Spark case - wordcount
- [pytoch foundation] torch Split() usage
- Recommended scheme for national production of electronic components of wireless keyboard
- Luogu p1858 [multi person knapsack] (knapsack seeking the top k optimal solution)
- IEEE Transactions on systems, man, and Cybernetics: Notes for systems (TSMC)
- List remove an element
猜你喜欢
Pixel 5 5g unlocking tutorial (including unlocking BL, installing edxposed and root)
Flink's important basics
Detailed explanation of life cycle component of jetpack
Inverse system of RC low pass filter
针对NFT的网络钓鱼
Supplément: annotation
Ali's ten-year technical experts jointly created the "latest" jetpack compose project combat drill (with demo)
Mysql50 basic exercises
Spark FAQ sorting - must see before interview
Excel protects worksheets and workbooks from damage
随机推荐
Installation and use of Apache bench (AB pressure test tool)
L2-011 玩转二叉树(建树+BFS)
协程与多进程的完美结合
Installation of zynq platform cross compiler
Installation du compilateur croisé de la plateforme zynq
程序员抱怨:1万2的工资我真的活不下去了,网友:我3千咋说
Phishing for NFT
leetcode008--实现strStr()函数
敏捷实践 | 提高小组可预测性的敏捷指标
win10, mysql-8.0.26-winx64. Zip installation
PIP3 installation requests Library - the most complete pit sorting
QML advanced (IV) - drawing custom controls
What is a data island? Why is there still a data island in 2022?
QML advanced (V) - realize all kinds of cool special effects through particle simulation system
Leetcode003 -- judge whether an integer is a palindrome number
Practice and exploration of knowledge map visualization technology in meituan
IDE idea automatic compilation and configuration of on update action and on frame deactivation
Spark optimization
Leetcode - > 1 sum of two numbers
Record the ThreadPoolExecutor main thread waiting for sub threads