Jump to content

Counting Folders


steveangelis

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.