steveangelis Posted April 27, 2009 Share Posted April 27, 2009 <?PHP $dir = "modules/"; $count = count(glob("" . $dir)); echo $count; ?> I hav a script I use to count files but now I want to minipulate it to count folders and I am not sure what else to do here. It does not count the folders. Does anyone know why? Link to comment https://forums.phpfreaks.com/topic/155881-counting-folders/ Share on other sites More sharing options...
premiso Posted April 27, 2009 Share Posted April 27, 2009 Valid flags: * GLOB_MARK - Adds a slash to each directory returned * GLOB_NOSORT - Return files as they appear in the directory (no sorting) * GLOB_NOCHECK - Return the search pattern if no files matching it were found * GLOB_NOESCAPE - Backslashes do not quote metacharacters * GLOB_BRACE - Expands {a,b,c} to match 'a', 'b', or 'c' * GLOB_ONLYDIR - Return only directory entries which match the pattern * GLOB_ERR - Stop on read errors (like unreadable directories), by default errors are ignored. From the glob manaul. Add the GLOB_ONLYDIR as the second parameter to your glob to get only directories. Link to comment https://forums.phpfreaks.com/topic/155881-counting-folders/#findComment-820518 Share on other sites More sharing options...
steveangelis Posted April 27, 2009 Author Share Posted April 27, 2009 <?PHP $dir = "styles"; foreach (count(glob($dir . "*", GLOB_ONLYDIR )) as $filename) { echo $filename; } ?> With this now I am trying to get the name of each of the folders. What do I change here? Link to comment https://forums.phpfreaks.com/topic/155881-counting-folders/#findComment-820526 Share on other sites More sharing options...
premiso Posted April 27, 2009 Share Posted April 27, 2009 Ok, take a step back and what do you want, as I do not think you know. You want to count the directories but now you want it to pull out file names? You are contradicting yourself. <?php $dir = "modules/"; $dirCount = count(glob($dir, GLOB_ONLYDIR)); echo "Number of directories under {$dir} is {$dirCount}<br />"; foreach (glob($dir . "*") as $filename) { echo $filename . "<br />"; } ?> So if that is not what you want, what exactly do you want? As I took it from this: I hav a script I use to count files but now I want to minipulate it to count folders Tells me that the above code I just posted solves your problem... Link to comment https://forums.phpfreaks.com/topic/155881-counting-folders/#findComment-820539 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.