NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page how to show how many files are in a directory thread

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 02-18-2006, 12:41 PM THREAD STARTER               #1 (permalink)
Senior Member
 
Joseph's Avatar
Join Date: Dec 2004
Location: Ireland
Posts: 2,684
Joseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond repute
 


Animal Cruelty 9/11/01 :: Never Forget Find Marrow Donors! Save The Children Save The Children Save The Children Ethan Allen Fund Baby Health Child Abuse Cancer AIDS/HIV Autism Autism Lou Gehrig's Disease (ALS) Parkinson's Disease Alzheimer's Cancer Save a Life Cancer Cancer Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009

how to show how many files are in a directory


Does anyone have the code to display how many files are in a folder on your website?

Example if i stored my images in a folder called images:

We currently host: 80 photos

Any idea how to do this?

Thanks

Joseph
Joseph is offline  
Old 02-18-2006, 01:58 PM   #2 (permalink)
NamePros Regular
 
Tree's Avatar
Join Date: Feb 2006
Location: Atlanta, GA, USA
Posts: 335
Tree will become famous soon enoughTree will become famous soon enough
 



Here's a (modified) example from php.net

PHP Code:
<?php
$dir 
"/etc/php5/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
   if (
$dh opendir($dir)) {
       while ((
$file readdir($dh)) !== false) {
????: NamePros.com http://www.namepros.com/programming/168897-how-show-how-many-files-directory.html
           
$num_of_files++;
       }
       
closedir($dh);
   }
}
echo 
"We host: $num_of_files";
?>
Tree is offline  
Old 02-18-2006, 02:28 PM   #3 (permalink)
Senior Member
 
superprogrammer's Avatar
Join Date: Aug 2004
Location: Washington
Posts: 4,327
superprogrammer has much to be proud ofsuperprogrammer has much to be proud ofsuperprogrammer has much to be proud ofsuperprogrammer has much to be proud ofsuperprogrammer has much to be proud ofsuperprogrammer has much to be proud ofsuperprogrammer has much to be proud ofsuperprogrammer has much to be proud of
 



Great!!
__________________
Download youtube videos at www.HugYouTube.com -NO LINKS TO PARKED PAGES-
Anonymous access at www.Banned.net
superprogrammer is offline  
Old 02-18-2006, 02:32 PM THREAD STARTER               #4 (permalink)
Senior Member
 
Joseph's Avatar
Join Date: Dec 2004
Location: Ireland
Posts: 2,684
Joseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond repute
 


Animal Cruelty 9/11/01 :: Never Forget Find Marrow Donors! Save The Children Save The Children Save The Children Ethan Allen Fund Baby Health Child Abuse Cancer AIDS/HIV Autism Autism Lou Gehrig's Disease (ALS) Parkinson's Disease Alzheimer's Cancer Save a Life Cancer Cancer Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
Thanks
Joseph is offline  
Old 02-18-2006, 02:33 PM   #5 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
And here's a modified version of Tree's modified PHP.net version...
PHP Code:
<?php

$dir 
"/etc/php5/";

// Open a known directory, and proceed to read its contents
if(is_dir($dir))
{
  if(
$dh opendir($dir))
  {
    while((
$file readdir($dh)) !== false)
????: NamePros.com http://www.namepros.com/showthread.php?t=168897
    {
      if(
$file != "." && $file != "..")
      {
        
$num_of_files++;
      }
    }
    
closedir($dh);
  }
}
echo 
"We host: $num_of_files";

?>
Eric is offline  
Old 02-18-2006, 02:45 PM   #6 (permalink)
NamePros Regular
 
Tree's Avatar
Join Date: Feb 2006
Location: Atlanta, GA, USA
Posts: 335
Tree will become famous soon enoughTree will become famous soon enough
 



Yeah, I guess SecondVersion's is better. Mine would be off by 2 if you're using Apache.
Tree is offline  
Old 02-19-2006, 08:09 AM THREAD STARTER               #7 (permalink)
Senior Member
 
Joseph's Avatar
Join Date: Dec 2004
Location: Ireland
Posts: 2,684
Joseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond repute
 


Animal Cruelty 9/11/01 :: Never Forget Find Marrow Donors! Save The Children Save The Children Save The Children Ethan Allen Fund Baby Health Child Abuse Cancer AIDS/HIV Autism Autism Lou Gehrig's Disease (ALS) Parkinson's Disease Alzheimer's Cancer Save a Life Cancer Cancer Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
thanks to all, using SV's =)
Joseph is offline  
Old 02-22-2006, 01:57 AM   #8 (permalink)
NamePros Member
Join Date: Feb 2006
Posts: 36
egkuan is an unknown quantity at this point
 



You could put it in a recursive function, and count files in subfolders as well.
egkuan is offline  
Closed Thread


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Greatest Image Gallery Tutorial Ever Wybe Webmaster Tutorials 5 12-20-2005 11:51 AM
PHP - Reading/displaying files from directory (help!) Virgil Programming 7 11-24-2005 12:33 PM
getting a list of files in a directory thread selfmindead CODE 2 04-18-2005 04:07 PM
PHP includes refererencing files from different directory thread FreeBaGeL Programming 6 03-08-2005 01:10 PM
public_html redhippo Web Design Discussion 8 02-27-2005 01:47 PM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 07:00 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger