PHP:检查目录是否为空,最好最简单的方法是什么? [英] PHP: What is the best and easiest way to check if directory is empty or not

查看:229
本文介绍了PHP:检查目录是否为空,最好最简单的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个根目录,具有100个动态生成的文件夹。随着时间的推移,这些文件夹中的某些文件夹将需要从系统中删除,条件是这个(ese)目录必须为空。什么是最好的最短,最简单和/或最有效的方法来实现?

解决方案

使用 glob

  if(count(glob(path / *))=== 0 ){// empty 

关于 glob 是它不返回 .. 目录。


I got a root directory with 100s of dynamically generated folders. As time goes some of these folders will need to be extirpated from system on the condition that this(ese) directories(s) must be empty. What would be the best shortest, easiest and/or most effective way to achieve that?

解决方案

Use glob :

if (count(glob("path/*")) === 0 ) { // empty

A nice thing about glob is that it doesn't return . and .. directories.

这篇关于PHP:检查目录是否为空,最好最简单的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆