Count Number of Files in a Directory / Folder – PHP

Hi Guys,
Today I share some useful topic related to two inbuilt function s in php for count number of files in php. The functions are:

  • glob(()
  • count()

Here’s a simple code of PHP code to get the total number of files in a directory using the glob() and count() function.



The first function to discuss is glob() it allows us to perform a search for pathnames using wildcards common to the best known shells.

The count function helps to count all files in specified directory.

count_folder



CODE





the Output will be

Total number Of files in a folder:4

We can count all the files in a folder and also count particular extension files(.jpeg / .php / .pdf etc)



The output will be:

Total number of php file in a folder :3



If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

Leave a Reply

Your email address will not be published. Required fields are marked *