Go Back   iGuides Webmasters and Business Talk > Web Site Development > Programming Discussion
Register FAQ Rules Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)   Report Post  
Old 11-17-2007, 05:12 AM
iGuides Addict
 
Join Date: Oct 2007
Location: Home Sweet Home
Posts: 53
3wlink is on a distinguished road
iTrader: (0)
Send a message via Yahoo to 3wlink
Default Count all files in a folder using PHP

Hello guys, i need to know how i can count all files in a folder. Of course, i need to count them along with their 'file types' -

like: .jpg - 12, .doc - 5, .txt - 2 etc.

Please let me know if any body can help me.

Thanks in advance
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)   Report Post  
Old 11-19-2007, 04:51 AM
iGuides Addict
 
Join Date: Oct 2007
Posts: 83
al-zabir is on a distinguished road
iTrader: (1)
Default

Hello friend,

Here is a tutorial about your question. Hope this will help you.
Go to

Small tutorial about reading contents of directory / folder with php

and please request for further tutorial in

http://www.iguides.org/forums/iguides-tutorials/

section

Thanks

Al - Zabir
__________________
GamesVenture
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)   Report Post  
Old 12-09-2007, 01:00 PM
Moderator
 
Join Date: Nov 2007
Posts: 18
anjuman is on a distinguished road
iTrader: (0)
Default

Hi al-zabir!
I have just read your tutorials. It's great! Thank you for your excellent tutorials.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)   Report Post  
Old 12-22-2007, 09:04 AM
Newbie
 
Join Date: Dec 2007
Location: Florida
Posts: 8
KarenBlack is on a distinguished road
iTrader: (0)
Default

If you're running on a linux system you can just use the backtick operator to the "ls" system command and sort the data... here's a lowdown dirty example

Quote:
$dir = `ls -p /path/to/dir | grep -v '/'`;

$num_files = count( $dir_contents = explode("\n", $dir) )-1;

echo "<b>Number of files :</b> $num_files <br /><br /><b>Filenames</b> <br />";

foreach ( $dir_contents as $filename ){
$file_ext = chop(substr( $filename, strrpos( $filename, "." ), strlen($filename)));
if ( $file_ext != '') {
$extensions[$file_ext] = ( $extensions[$file_ext] == 0) ? $extensions[$file_ext] = 1 : $extensions[$file_ext] = $extensions[$file_ext]+1;
echo "$filename<br />";
}

}

echo "<br /><b>Extension count :</b><br />";
foreach ( $extensions as $key => $value ){
echo "$key : $value <br />";
}
If you're running on windoze server, well, you're SOL.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)   Report Post  
Old 12-22-2007, 09:17 AM
Newbie
 
Join Date: Dec 2007
Location: Florida
Posts: 8
KarenBlack is on a distinguished road
iTrader: (0)
Default

Otherwise al-zabir's tutorial is a cross platform compliant solution, however, if you're running linux, there's nothing faster than utilizinf system commands. Especially if you have a highly trafficed site where milliseconds of processing time add up. This goes back to old school Perl programming where utilizing pipes and system commands can really add speed and optimization than using PHP built-in functions.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:23 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0

Ad Management by RedTyger