[PHP] Counting files in directory and subdirectory!

2006-01-25 Thread Nicholas Couloute
I want a script where it will count all the amrs in a folder and it's 
sub folders like this setup:

amrs 
50 cent  amrs
nitty  amrs
bob  amrs
How would I do this?
~Nick Couloute
co-owner/Web Designer
Sidekick2Music.Com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Counting files in directory and subdirectory!

2006-01-25 Thread tomasz abramowicz

start here: http://www.php.net/readdir

check out as well: 'string functions' for finding 'amrs'
and loops to make recursive search...

t.

Nicholas Couloute wrote:
I want a script where it will count all the amrs in a folder and it's 
sub folders like this setup:

amrs 
50 cent  amrs
nitty  amrs
bob  amrs
How would I do this?
~Nick Couloute
co-owner/Web Designer
Sidekick2Music.Com



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Counting files in directory and subdirectory!

2006-01-25 Thread Weber Sites LTD
You can start with looking at some code examples that do similar things :

Directory browser
http://www.weberdev.com/get_example-1539.html 

How to get a dir listing of the current dir of php script in an array 
http://www.weberdev.com/get_example-1855.html

filesystem Show Files Script
http://www.weberdev.com/get_example-4240.html

Sincerely 
 
berber 
 
Visit the Weber Sites Today, 
To see where PHP might take you tomorrow. 
PHP code examples : http://www.weberdev.com 
PHP  MySQL Forums : http://www.weberforums.com
Learn PHP  MySQL Playing Trivia : http://www.webertrivia.com
PHP Web Logs : http://www.weberblogs.com 
Web Development Index http://www.weberindex.com 
Web Templates http://www.webertemplates.com
Search for PHP Code from your browser http://toolbar.weberdev.com 
Free Uptime Monitor : http://uptime.weberdev.com
PHP content for your site : http://content.weber-sites.com


-Original Message-
From: Nicholas Couloute [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, January 25, 2006 9:41 PM
To: php-general@lists.php.net
Subject: [PHP] Counting files in directory and subdirectory!

I want a script where it will count all the amrs in a folder and it's sub
folders like this setup:
amrs 
50 cent  amrs
nitty  amrs
bob  amrs
How would I do this?
~Nick Couloute
co-owner/Web Designer
Sidekick2Music.Com

--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Counting files in directory and subdirectory!

2006-01-25 Thread Nicholas Couloute
I have used these functions but how would I count them! here is my 
attempt that doesn't work!:

$count = 0;
$dir = /amrs;
$files1 = scandir($dir);
if ($files1 !== '.'  $files1 !== '..') {
foreach ($files1 as $files2){
$dir2 = /amrs/$files2;
$files3 = scandir($dir2);
if ($files3 !== '.'  $files3 !== '..') {
foreach ($files3 as $files4){
$dir3 = /amrs/$files2/$files4;
$files5 = scandir($dir3);
if ($files5 !== '.'  $files5 !== '..') {
foreach ($files5 as $files6){
$count++;
}
}
}
}
}
}
echo $count;

~Nick Couloute
co-owner/Web Designer
Sidekick2Music.Com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Counting files in directory and subdirectory!

2006-01-25 Thread Nicholas Couloute
here is what I tried but it doesn't work! any advice suggestions or 
something?


$count = 0;
$dir = /amrs;
$files1 = scandir($dir);
if ($files1 !== '.'  $files1 !== '..') {
foreach ($files1 as $files2){
$dir2 = /amrs/$files2;
$files3 = scandir($dir2);
if ($files3 !== '.'  $files3 !== '..') {
foreach ($files3 as $files4){
$dir3 = /amrs/$files2/$files4;
$files5 = scandir($dir3);
if ($files5 !== '.'  $files5 !== '..') {
foreach ($files5 as $files6){
$count++;
}
}
}
}
}
}
echo $count;
~Nick Couloute
co-owner/Web Designer
Sidekick2Music.Com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Counting files in directory and subdirectory!

2006-01-25 Thread David Tulloh
That is some nasty code...
Anything that has repitition like that needs a substantial rewrite, but
I'm guessing that you know that, hence the e-mail.

I just knocked up the following function, powered by the magic of
recursion.  It should be close to what you were trying to do.


function count_files($path) {
$number_of_files = 0;
foreach(scandir($path) as $dir) {
if($dir{0} == '.') continue; # Ignore hidden files
if(is_dir($path.'/'.$dir))
$number_of_files += count_files($path.'/'.$dir);
else
$number_of_files++;
}
return $number_of_files;
}

echo count_files(amrs);



David

Nicholas Couloute wrote:
 here is what I tried but it doesn't work! any advice suggestions or
 something?
 
 $count = 0;
 $dir = /amrs;
 $files1 = scandir($dir);
 if ($files1 !== '.'  $files1 !== '..') {
 foreach ($files1 as $files2){
 $dir2 = /amrs/$files2;
 $files3 = scandir($dir2);
 if ($files3 !== '.'  $files3 !== '..') {
 foreach ($files3 as $files4){
 $dir3 = /amrs/$files2/$files4;
 $files5 = scandir($dir3);
 if ($files5 !== '.'  $files5 !== '..') {
 foreach ($files5 as $files6){
 $count++;
 }
 }
 }
 }
 }
 }
 echo $count;
 ~Nick Couloute
 co-owner/Web Designer
 Sidekick2Music.Com
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php