[英]Echo all the folder names in a folder
I want to print all the folder names inside a parent folder. 我想在父文件夹中打印所有文件夹名称。 The current issue I am facing is, though I have 400+ folders in a folder only 257 are getting printed. 我面临的当前问题是,尽管我在一个文件夹中有400多个文件夹,但只有257个正在打印。 Again, this is not at all issue related with permissions. 同样,这与权限无关。
Please find my code below: 请在下面找到我的代码:
$newdir = "content/";
$dircnt = 0;
// Open a known directory, and proceed to read its contents
if (is_dir($newdir)) {
if ($dh = opendir($newdir)) {
while (($file = readdir($dh)) !== false) {
$dircnt++;
if(filetype($newdir. $file) == 'dir') {
echo "filename: $file : filetype: " . filetype($newdir. $file) . "dircnt:" .$dircnt. "<br>";
}
}
closedir($dh);
}
}
}
You can use glob()
function - returns an array containing the matched files/directories, an empty array if no file matched or FALSE on error. 您可以使用glob()
函数-返回一个包含匹配文件/目录的数组,如果没有匹配的文件,则返回一个空数组,否则返回FALSE。
$filesDirectories = glob($newdir.'*', GLOB_BRACE);
foreach($filesDirectories as $key=>$file) {
echo "$file size " . filesize($file) . "\n";
}
I would use glob: 我会使用glob:
$newdir = "content/";
$dirs = glob($newdir.'*',GLOB_ONLYDIR);
foreach($dirs as $index=>$dir){
echo "filename ". $dir." filetype ".filetype($newdir.$dir)." dircnt:".($index+1)."<br/>";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.