Jump to content

how to count directories if a folder?


hellonoko

Recommended Posts

I have a directory /subdomains/

 

And inside of that directory is a user folder /mike/  /bob/ /tim/  etc.

 

I have written a simple scrip to count the files inside the user folder:

 

<?php

session_start();

echo "<title>count</title>";

$dir = "subdomains/" . $_SESSION['login'] . "/filez/";

$count = count(glob($dir . "*.mp3"));

echo $_SESSION['login'];
echo '<br>';
echo $count;

?>

 

 

What I am now trying to do is put this script inside a script that can go through each directory and count the number of files and then sort them by most to least.

 

So I can return:

 

Mike 10

Bob 8

Jim 5

 

and so on.

 

I think I need to place it all in a loop that places each directory count into a array as it goes through the directories in /subdomains/ but I am not sure how to work with directories in that way.

 

Thanks in advance,

ian

Link to comment
https://forums.phpfreaks.com/topic/127809-how-to-count-directories-if-a-folder/
Share on other sites

here's a simple example you can explore

<?php
$path = realpath('/directory');
$iterator = new RecursiveDirectoryIterator($path);
foreach (new RecursiveIteratorIterator($iterator, 2) as $path){
     if($path->isDir()){
        echo $path."\n";
        //code to gather info
     }
} 

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.