Count All Files in Given Directory and Subdirectories using PHP

RecursiveDirectoryIterator class

<?php

$rootDir = 'test_dir';

$it = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($rootDir, RecursiveDirectoryIterator::SKIP_DOTS)
);

$numberOfFiles = iterator_count($it);

echo $numberOfFiles;

Leave a Comment

Cancel reply

Your email address will not be published.