Looking to count files in two folders

Discussion in 'PHP' started by Foxiee, May 3, 2011.

  1. #1
    Hi,

    Searching for a way to count files in two folders, what I want to do is display on my site

    "Files in Folder A: XXX
    Size of of files in folder A: XXX
    Files in Folder B: XXX
    Size of files in folder B: XXX
    Total amount of files: XXX
    Size of all files: XXX"

    Thanks for help.
     
    Foxiee, May 3, 2011 IP
  2. ap2010

    ap2010 Guest

    Messages:
    41
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can use the php's dir() function to iterate over a directory and use filesize() function to find size of each file. If you want recursive search (calculate files inside subfolders) then glob() might be better.
     
    ap2010, May 3, 2011 IP
  3. Mak3MyDay

    Mak3MyDay Peon

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You can use readdir to get and count the number of files..
    Here's the link: http://php.net/manual/en/function.readdir.php
     
    Mak3MyDay, May 4, 2011 IP
  4. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #4
    Have you ever heard of the DirectoryIterator class provided by the SPL (Standard PHP Library) ?
     
    joebert, May 4, 2011 IP