28, May 2012

a script that counts directories and displays that number - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: a script that counts directories and displays that number
« previous next »
Pages: [1] Print
Instabuck - The easy way to sell digital products online

Author Topic: a script that counts directories and displays that number  (Read 1052 times)
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« on: Dec 13, 2005, 09:03:25 pm »

ok besides the delete file script i need a small script that can simply count the number of sub-directories inside a directory, and show that number on a page, for xample. i provide free ad-supported hosting with a crappy CGI script, and when a user signs up, it creates their directory. all the script has to do is count those directories and it provides the number of actual accounts on the web hosting sign up page. seems simple enough to me but i cant find anything about it.


Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #1 on: Dec 13, 2005, 09:10:24 pm »

Here you are :

Code:
<?php
$dir 
"PathToYourDirectoryHere/";
$cnt 0;

if (
$handle opendir($dir) )
 {
    while (
false !== ($file readdir($handle))) 
    { 
        if ( 
is_dir $dir $file ) )
        {
            
$cnt ++;
        }
    }
    
closedir($handle); 
}

echo 
$cnt ' accounts';
?>


Note that $dir = "PathToYourDirectoryHere/"; should end with a slash (/)

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #2 on: Dec 13, 2005, 09:16:46 pm »

Warning: opendir(http://justinlove.net/members/): failed to open dir: not implemented in /hsphere/local/home/meth0d42/justinlove.net/v2/administration/custom_pages.php(71) : eval()'d code on line 5


Last blog : phpHaze 1.59.1 in Development
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #3 on: Dec 13, 2005, 09:19:51 pm »

got it to work but it displays 12 accounts when there are really 10


Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #4 on: Dec 13, 2005, 09:24:55 pm »

First of all you should use this with a real directory not a url.

eg.

$dir ="/hsphere/local/home/meth0d42/justinlove.net/v2/administration/";

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #5 on: Dec 13, 2005, 09:25:51 pm »

Yeah I forgot that.

You should
Code:
<?php
echo ($cnt 2) . ' accounts';

(last line)

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Cyberpunk Wannabe
*
Gender: Male
Posts: 39
172 credits
Members referred : 0



« Reply #6 on: Dec 14, 2005, 02:36:39 pm »

This is because it will count as directory the current and the parrent directory.
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1525
6359 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #7 on: Dec 14, 2005, 05:26:30 pm »

That is right... Just make sure that you don't count the directories that match . and ..


Last blog : Canonical URL Links / Tags
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=988
Tags : directories hosting Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: a script that counts directories and displays that number
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 11:39:58 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.