我想检查一个文件夹是否至少包含1个真实文件。我试过这个代码:如何检查文件夹是否仅包含使用php的文件
$dir = "/dir/you/want/to/scan";
$handle = opendir($dir);
$folders = 0;
$files = 0;
while(false !== ($filename = readdir($handle))){
if(($filename != '.') && ($filename != '..')){
if(is_dir($filename)){
$folders++;
} else {
$files++;
}
}
}
echo 'Number of folders: '.$folders;
echo '<br />';
echo 'Number of files: '.$files;
当在文件夹中scan
是1个子文件夹和2个真实文件;上面的代码给了我作为输出:
Number of folders: 0
Number of files: 3
如此看来,一个子文件夹被视为一个文件。但我只想要检查真实文件。我怎么能做到这一点?
内做到这一点帮助您:https://secure.php.net/manual/en/ function.scandir.php#87527?并检查数组是否为空()。 – 2016-06-07 11:38:40
[PHP:如何在没有列出子目录的情况下列出目录中的文件]的可能副本(http://stackoverflow.com/questions/7684881/php-how-to-list-files-in-a-directory-without-list -subdirectories) – Thamilan