
Desde já agradeco ^^
Posted 24/05/2007, 20:52
Posted 25/05/2007, 02:37
<?php set_time_limit(0); class DirSize { var $_files = 0; function DirSize($path, $recursively = false) { if (!is_dir($path)) { throw new Exception('Invalid directory path!'); } $this->_scan($path, $recursively); } function _scan($path, $recursively) { $handle = opendir($path); while (false !== ($filename = readdir($handle))) { $filename = "$path/$filename"; $basename = basename($filename); if (is_dir($filename)) { if ($basename != '.' && $basename != '..' && $recursively === true) { $this->_scan($filename, true); } } else { $this->_files++; } } closedir($handle); } function getFileCount() { return $this->_files; } } $DirSize = new DirSize('.', true); print $DirSize->getFileCount(); ?>
<?php set_time_limit(0); class DirSize { private $_files = 0; public function __construct($path, $recursively = false) { if (!is_dir($path)) { throw new Exception('Invalid directory path!'); } $this->_scan($path, $recursively); } private function _scan($path, $recursively) { $handle = new RecursiveDirectoryIterator($path); while ($handle->valid()) { if ($handle->isDir()) { if (!$handle->isDot() && $recursively === true) { $this->_scan($handle->getPathName(), true); } } else { $this->_files++; } $handle->next(); } } public function getFileCount() { return $this->_files; } } $DirSize = new DirSize('.', true); print $DirSize->getFileCount(); ?>PS: Não usei glob() por questões que foram contra minha vontade; ela não soube contar direito, apenas isso.
Posted 25/05/2007, 04:06
Edição feita por: VultoBR, 25/05/2007, 04:08.
Posted 25/05/2007, 04:55
Mas o primeiro (para PHP 4) também funcionou, né? Era pra funcionar...Opa
o 2º funcinou perfeitamente obrigado pela ajuda, eu tentei fazer de diversas formar, e pelo que vejo é bem mais complicado do que eu pensava já que nao manjo nada de OOP , obrigado mesmo
.
Abraçost+
Posted 25/05/2007, 05:02
Posted 25/05/2007, 05:50
Estranho, aqui o código para PHP 4 funciona. Utilizo PHP 5.2.2.Bom já que você comentou, eu tentei utilizar o 1º e ele fico carregando, e depois aparece "Pagina nao encontrada".
Ah, pode deixar vou ler este capitulo concertezaObrigado pela dica ^^
[]'s T+ xD
Posted 25/05/2007, 15:45
Estranho, aqui o código para PHP 4 funciona. Utilizo PHP 5.2.2.Bom já que você comentou, eu tentei utilizar o 1º e ele fico carregando, e depois aparece "Pagina nao encontrada".
Ah, pode deixar vou ler este capitulo concertezaObrigado pela dica ^^
[]'s T+ xD
Tu não tirou o set_time_limit(0); do código não, né? Pois se tirar ele e a função demorar mais que os 30 segundos padrão do PHP acontecerá isso mesmo...
[]’s
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)