I am a complete nub when it comes custom PHP coding, I know how to edit things and what not. Anyway, can someone show me a code that counts the number of folders in a directory on a server and then display the number in text format, I've looked across the net and found nothing, thanks
**Code to count # of folders in a directory and display it**
Moderator: General Moderators
- FormatteD_C
- Forum Newbie
- Posts: 10
- Joined: Tue Oct 21, 2003 5:08 pm
- Location: Ohio
- Contact:
**Code to count # of folders in a directory and display it**
Hi,
I am a complete nub when it comes custom PHP coding, I know how to edit things and what not. Anyway, can someone show me a code that counts the number of folders in a directory on a server and then display the number in text format, I've looked across the net and found nothing, thanks
I am a complete nub when it comes custom PHP coding, I know how to edit things and what not. Anyway, can someone show me a code that counts the number of folders in a directory on a server and then display the number in text format, I've looked across the net and found nothing, thanks
Depends on your version of PHP but if you're using PHP >= 4.3.0 then you could do:
Code: Select all
echo count(glob('/path/to/dir/*'), GLOB_ONLYDIR);- FormatteD_C
- Forum Newbie
- Posts: 10
- Joined: Tue Oct 21, 2003 5:08 pm
- Location: Ohio
- Contact:
Nope
Its version 4.2.3
Ah ok, then try this:
Code: Select all
$dirtocount = 'full/path/to/dir/to/count'; //put your directory here
$dircount = 0;
if ($handle = opendir($dirtocount)) {
while (false !== ($file = readdir($handle))) {
if(is_dir($dirtocount.'/'.$file)){
$dircount++;
}
}
closedir($handle);
}
echo $dircount;- FormatteD_C
- Forum Newbie
- Posts: 10
- Joined: Tue Oct 21, 2003 5:08 pm
- Location: Ohio
- Contact:
:P
I used the script you gave me and I get this line:
Warning: OpenDir: Invalid argument (errno 22) in C:\Webserver\apache\htdocs\update.php on line 35
line 35 is - if ($handle = opendir($dirtocount)) {
/htdocs is the directory with the folders I want it to count
Thanks for helping me out markl999
Warning: OpenDir: Invalid argument (errno 22) in C:\Webserver\apache\htdocs\update.php on line 35
line 35 is - if ($handle = opendir($dirtocount)) {
/htdocs is the directory with the folders I want it to count
Thanks for helping me out markl999
- FormatteD_C
- Forum Newbie
- Posts: 10
- Joined: Tue Oct 21, 2003 5:08 pm
- Location: Ohio
- Contact:
!!!
Works like a charm! Thanks. The path I used was:
'/Webserver/apache/htdocs'
'/Webserver/apache/htdocs'