[PHP] dir size

2003-10-03 Thread Ms Carlsson
is it possible to count  a size of a dir and all sub dirs in php ? and if, 
how?

thanx

_
Lättare att hitta drömresan med MSN Resor http://www.msn.se/resor/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] dir size

2003-10-03 Thread Jay Blanchard
[snip]
is it possible to count  a size of a dir and all sub dirs in php ? and
if, 
how?
[/snip]

$foo = exec(du -h);

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



RE: [PHP] dir size

2003-10-03 Thread Robert Cummings
On Fri, 2003-10-03 at 14:45, Jay Blanchard wrote:
 [snip]
 is it possible to count  a size of a dir and all sub dirs in php ? and
 if, 
 how?
 [/snip]
 
 $foo = exec(du -h);
 

Hmmm this solution would appear to include the file sizes :D

Rob
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] dir size

2003-10-03 Thread Gabriel Guzman
On Friday 03 October 2003 11:48 am, Robert Cummings wrote:
 On Fri, 2003-10-03 at 14:45, Jay Blanchard wrote:
  [snip]
  is it possible to count  a size of a dir and all sub dirs in php ? and
  if,
  how?
  [/snip]
 
  $foo = exec(du -h);

 Hmmm this solution would appear to include the file sizes :D

man du  :D

gabe.

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



Re: [PHP] dir size

2003-10-03 Thread Curt Zirzow
* Thus wrote Ms Carlsson ([EMAIL PROTECTED]):
 is it possible to count  a size of a dir and all sub dirs in php ? and if, 
 how?

Dir size is  rather vague. Are you wanting how many items are in
the dir? or how many bytes is allocated for it? or how many bytes
are actually used in the dir? What is the total sum of all the
files space used inside the dir? and does that include the
sub directories sizes?


Curt
-- 
List Stats: http://zirzow.dyndns.org/html/mlists/php_general/

I used to think I was indecisive, but now I'm not so sure.

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



Re: [PHP] dir size

2003-10-03 Thread Robert Cummings
On Fri, 2003-10-03 at 15:02, Gabriel Guzman wrote:
 On Friday 03 October 2003 11:48 am, Robert Cummings wrote:
  On Fri, 2003-10-03 at 14:45, Jay Blanchard wrote:
   [snip]
   is it possible to count  a size of a dir and all sub dirs in php ? and
   if,
   how?
   [/snip]
  
   $foo = exec(du -h);
 
  Hmmm this solution would appear to include the file sizes :D
 
 man du  :D

I was being facetious.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



RE: [PHP] dir size

2003-10-03 Thread Jay Blanchard
[snip]
   $foo = exec(du -h);
 
  Hmmm this solution would appear to include the file sizes :D
 
 man du  :D

et du?

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



Re: [PHP] dir size

2003-10-03 Thread Nathan Taylor
Hey, I think I mis-understood you and my first version didn't do what you want, so I 
added what you needed.

?php

function DirStat($directory) {
 global $FolderCount, $FileCount, $FolderSize;

 chdir($directory);
 $directory = getcwd();
 $open = opendir($directory);
 if($open) {
  while($file = readdir($open)) {
   if($file == .. || $file == .) continue;
   if(is_file($file)) {
$FileCount++;
$FolderSize += filesize($file);
   } elseif(is_dir($file)) {
$FolderCount++;
   }
  }
  if($FolderCount  0) {
   $open2 = opendir($directory);
   while($folders = readdir($open2)) {
$folder = $directory./.$folders;
if($folders == .. || $folders == .) continue;
if(is_dir($folder)) {
 echo DirStat($folder);
}
   }
   closedir($open2);
  }
  closedir($open);
 }
}

function ByteSize($bytes) {
  $size = $bytes / 1024;
  if($size  1024){
   $size = number_format($size, 2);
   $size .= kb;
  } else {
   if($size / 1024  1024) {
$size = number_format($size / 1024, 2);
$size .= mb;
   } else {
$size = number_format($size / 1024 / 1024, 2);
$size .= gb;
   }
  }
  return $size;
 }

$dir = getcwd();
DirStat(tmp, 0);
chdir($dir);

$FolderSize = ByteParse($FolderSize);

echo $FileCount;
echo /p\n;
echo $FolderSize;

?


The DirStat() function is almost unchanged except that it now passes out the byte size 
of the directories read. I also threw in a chdir() to get you back to your working 
directory. The major addition here is the ByteSize() function.  That function takes 
the integer which is your total size of the directory and converts it into a nice 
formatted number either in kb, mb, or gb accordingly.  You'll find it uses true file 
size as well, not industry standard sizing.

Enjoy,
Nathan Taylor
  - Original Message - 
  From: Ms Carlsson 
  To: [EMAIL PROTECTED] 
  Sent: Friday, October 03, 2003 2:44 PM
  Subject: [PHP] dir size


  is it possible to count  a size of a dir and all sub dirs in php ? and if, 
  how?

  thanx

  _
  Lättare att hitta drömresan med MSN Resor http://www.msn.se/resor/

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



Re: [PHP] dir size

2003-10-03 Thread Eugene Lee
On Fri, Oct 03, 2003 at 02:14:14PM -0500, Jay Blanchard wrote:
: [snip]
:   
:$foo = exec(du -h);
:  
:   Hmmm this solution would appear to include the file sizes :D
:  
:  man du  :D
: 
: et du?

LMAO!  :-D

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