Forum Moderators: coopster

Message Too Old, No Replies

counting and display no. of images in several directories

         

Daku1

7:51 pm on Jun 19, 2009 (gmt 0)

10+ Year Member



Dear all
I am an absolute newbie as far as php goes but I have just bought some books to get me started in my old age :-)

I would very much appreciate it if someone could help with the following requirement.
An academic reference website of which I am administrator has literally thousands of images and text files. I need to know how many .txt files are in the various 2nd level folder sections. Each individual entry has 1 or 2 images plus thumbnails but only 1 txt file per entry, so a count of the txt files would give a more accurate "reading".

The folder structure is as follows (folder names changed for clarity):

- main folder
- historical period1
- lots of individual sub-folders of "regions", each folder containing numerous entries comprising of images, thumbnails and 1 txt file per entry. Some folders have more entries than others.
- historical period2
- lots of individual sub-folders of "regions", each folder containing numerous entries comprising of images, thumbnails and 1 txt file per entry. Some folders have more entries than others.
- historical period3
- lots of individual sub-folders of "regions", each folder containing numerous entries comprising of images, thumbnails and 1 txt file per entry. Some folders have more entries than others.

etc

So what I would need to find out using a little php script is the information
- Historical Period 1: .... txt files
- Historical Period 2: .... txt files
- Historical Period 3: .... txt files
etc.

I have managed to put together a little script but this needs the name of e.g. the region and I have so many regions it would take ages to keep changing it and running it.

Can anyone help ?

Many thanks from a newbie girly.

coopster

1:26 pm on Jun 20, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Daku1.

PHP has a great toolset for working with Directories [php.net]. And although you can recursively iterate directories with the functions found on those pages, the more advanced Standard PHP Library (SPL) [php.net] has built in iteration tools, one of them extended particularly for directory iteration.

Daku1

12:24 am on Jun 21, 2009 (gmt 0)

10+ Year Member



Ah thankyou, I will have a look there. I managed to get something working using

$fc01 = count(glob("../Period_1/*/*.txt"));
echo "<b>"."Period_1:"."</b>"." $fc01\n"."<br>";

$fc02 = count(glob("../Period_2/*/*.txt"));
echo "<b>"."Period_1:"."</b>"." $fc02\n"."<br>";

etc for all the sections then adding them together for the final count. This "with a little help from my friends"..

I just got "PHP for Dummies" to get me started...

coopster

12:25 pm on Jun 22, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Cool. Here are some notes on glob too:
[webmasterworld.com...]