imagewiz Posted February 1, 2009 Share Posted February 1, 2009 I am using the following code to return file count in directories, but the code returns 0 until 2 files are found. If I change if ($total_files_home <= 1) to if ($total_files_home <= 0) or if ($total_files_home == 0) it returns 1 file even if directory is empty. What am I doing wrong? I am a novice in php. Thank you for any help or a better solution. <?php $total_files_home = 0; $total_files_home = count(glob("../users/$username/{*.*}", GLOB_BRACE)); if ($total_files_home <= 1) $total_files_home = 0; else $total_files_home = $total_files_home; echo '<a href="manager.php?efolder=home">'; echo '<img src="gfx/FolderIconV2.gif" border="0" alt="Home" width="60" height="50"><br>Home<br></a>( '.$total_files_home.' )<br><br></font>'; foreach(glob('../users/'.$username.'/*', GLOB_ONLYDIR) as $dir) { $dir = str_replace('../users/'.$username.'/', '', $dir); $total_files_sub = count(glob("../users/$username/$dir/{*.*}", GLOB_BRACE)); if ($total_files_sub <= 1) $total_files_sub = 0; else $total_files_sub = $total_files_sub; echo '<a href="manager.php?efolder='.$dir.'">'; echo '<font size=2>'; echo '<img src="gfx/FolderIconV2.gif" border="0" alt="'.$dir.'" width="60" height="50"><br>'.$dir.'<br></a>( '.$total_files_sub.' )<br><BR></font></a>'; } ?> Link to comment https://forums.phpfreaks.com/topic/143319-help-getting-correct-file-count-glob/ Share on other sites More sharing options...
cwarn23 Posted February 1, 2009 Share Posted February 1, 2009 Try the following: $username=''; $total_files_home = 0; $total_files_home = count(glob("../users/$username/{*.*}", GLOB_BRACE)); if ($total_files_home < 1) $total_files_home = 0; else $total_files_home = $total_files_home; echo '<a href="manager.php?efolder=home">'; echo '<img src="gfx/FolderIconV2.gif" border="0" alt="Home" width="60" height="50"><br>Home<br></a>( '.$total_files_home.' )<br><br></font>'; foreach(glob('../users/'.$username.'/*', GLOB_ONLYDIR) as $dir) { $dir = str_replace('../users/'.$username.'/', '', $dir); $total_files_sub = count(glob("../users/$username/$dir/{*.*}", GLOB_BRACE)); if ($total_files_sub <= 1) $total_files_sub = 0; else $total_files_sub = $total_files_sub; echo '<a href="manager.php?efolder='.$dir.'">'; echo '<font size=2>'; echo '<img src="gfx/FolderIconV2.gif" border="0" alt="'.$dir.'" width="60" height="50"><br>'.$dir.'<br></a>( '.$total_files_sub.' )<br><BR></font></a>'; } Link to comment https://forums.phpfreaks.com/topic/143319-help-getting-correct-file-count-glob/#findComment-751707 Share on other sites More sharing options...
imagewiz Posted February 1, 2009 Author Share Posted February 1, 2009 cwarn23..Thank you, but that returned the same. Link to comment https://forums.phpfreaks.com/topic/143319-help-getting-correct-file-count-glob/#findComment-751716 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.