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
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
     }
} 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.