[英]how to check if scandir() returns false in php
I will get to the point and explain what I am trying to accomplish then show you what I currently am using to achieve this. 我会指出重点,解释我要完成的工作,然后向您展示我目前正在使用的实现目标。
What I want is to check if directory has any files it at all. 我想要的是检查目录是否有任何文件。 Now I usually use readdir and use a while loop to go thru it and what not but I ran up scandir() and thought it would be a bit quicker to use.
现在,我通常使用readdir并使用while循环进行遍历,但不是,但是我运行了scandir()并认为使用起来会更快一些。
I am trying to use a logical operator for when scandir() fails. 我试图在scandir()失败时使用逻辑运算符。 So for example:
因此,例如:
if(false!==scandir($main_directory)){
//do something;
}
at first it seemed to work however when i implemented something else to be done solely when scandir() fails, it seems like it just ignores it and put it regardless. 起初它似乎可行,但是当我仅在scandir()失败时实施其他事情才能完成时,似乎它只是忽略了它,然后放了它。
any thoughts? 有什么想法吗?
Try defining a variable for the scandir function and use it as a condition in your if statement. 尝试为scandir函数定义一个变量,并将其用作if语句中的条件。 For example
例如
$scan_result=scandir($main_directory);
if(scan_result == false)
{
//Do something
}
else
{
//Do something else
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.