Current location: Hot Scripts Forums » Programming Languages » PHP » How to count total files inside folder + subfolder?


How to count total files inside folder + subfolder?

Reply
  #1 (permalink)  
Old 06-22-03, 11:53 AM
kevin kevin is offline
Newbie Coder
 
Join Date: Jun 2003
Location: USA
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
How to count total files inside folder + subfolder?

Hello !

This is my folder tree

MAIN_FOLDER
.......file1.txt
.......file2.txt
.......file3.html
...SUBFODER_1
.......file1.txt
.......file2.html
...SUBFODER_2
.......file1.txt
.......file2.html
...SUBFODER_3
.......file1.txt
.......file2.html

Please help me to write the PHP code can count total of files (txt + html) wwhich were stored inside MAIN_FOLDER

Thanks for your help
Reply With Quote
  #2 (permalink)  
Old 06-22-03, 12:50 PM
ChristGuy ChristGuy is offline
Operations Support Develo
 
Join Date: Jun 2003
Location: Rivonia, South Africa
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Greetingz...

I'll guess you're looking for something like this:
PHP Code:

<?php

  
function CountDir($aDir$aRecurse)
  {
    
$Count 0;

    
$d dir($aDir);

    while (
$Entry $d->Read())
    {
      if (!((
$Entry == "..") || ($Entry == ".")))
      {
        if (
Is_Dir($aDir '/' $Entry))
        {
          if (
$aRecurse)
          {
            
$Count += CountDir($aDir '/' $Entry$aRecurse);
          }
        }
        else
        {
          
$Count++;
        }
      }
    }
    
    return 
$Count;
  }
?>
Usage:
PHP Code:

  echo CountDir($_SERVER["DOCUMENT_ROOT"], True); // Echo's 9


  
echo CountDir($_SERVER["DOCUMENT_ROOT"], False); // Echo's 3 
hope that helps...
__________________
Till We Meet Again...
Clifford W. Hansen
Aspivia (Pty) Ltd

"We Have Seen Strange Things Today!" Luke 5:26
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help me to count file *.txt only inside folder+ subfolder kevin PHP 3 07-25-03 02:22 PM
edit php in Squirrelmail jrcortrightiii PHP 1 07-10-03 02:08 PM


All times are GMT -5. The time now is 08:20 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.