4, December 2008

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

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ 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

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



« on: Dec 13, 2005, 10: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.

Visit through proxy Visit through proxy Visit through proxy

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



« Reply #1 on: Dec 13, 2005, 10: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 Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #2 on: Dec 13, 2005, 10:16:46 PM »

Warning: opendir(http://justinlove.net/members/ Visit through proxy): 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

Visit through proxy Visit through proxy Visit through proxy

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



« Reply #3 on: Dec 13, 2005, 10:19:51 PM »

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

Visit through proxy Visit through proxy Visit through proxy

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



« Reply #4 on: Dec 13, 2005, 10: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 Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8269
42601 credits
Members referred : 3



« Reply #5 on: Dec 13, 2005, 10: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 Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Cyberpunk Wannabe
*
Gender: Male
Posts: 39
172 credits
Members referred : 0



« Reply #6 on: Dec 14, 2005, 03:36:39 PM »

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


Gimme all your cookies!!!


« Reply #7 on: Dec 14, 2005, 06:26:30 PM »

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


Last blog : Site of the Month - August 2007
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....

Topic sponsors:
Get a permanent link here for $1.99!


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?
Dec 04, 2008, 08:35:01 AM





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!





Readers

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