Posted By

duzenz on 02/01/12


Tagged

php file folder count directory opendir Readdir


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Priestd09


Getting files, folders, file count, folder count in a directory with php


 / Published in: PHP
 

Getting files, folders, file count, folder count in a directory with php and writing them to a web page

  1. <?php
  2. $folderCount = $fileCount = 0;
  3. //. means current directory
  4. //if you wanna a learn a folders inside use opendir('path')
  5. if ($handle = opendir('.')) {
  6. while (false !== ($entry = readdir($handle))) {
  7. if ($entry != "." && $entry != "..") {
  8. if (is_dir($entry)) {
  9. echo "Folder => " . $entry . "<br>";
  10. $folderCount++;
  11. } else {
  12. echo "File => " . $entry . "<br>";
  13. $fileCount++;
  14. }
  15. }
  16. }
  17. echo "<br>==============<br>";
  18. echo "Total Folder Count : " . $folderCount . "<br>";
  19. echo "Total File Count : " . $fileCount;
  20. closedir($handle);
  21. }
  22. ?>

Report this snippet  

You need to login to post a comment.