Files
php_8/dirs/dir_rewind.php
2022-07-29 17:37:18 +03:00

31 lines
919 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
$dirname = "./";
$cat = dir($dirname);
$file_count = 0;
$dir_count = 0;
// Подсчитываем количество файлов и подкаталогов
while (($file = $cat->read()) !== false) {
if (is_file($dirname.$file)) $file_count++;
else $dir_count++;
}
// Не учитываем служебные подкаталоги
$dir_count = $dir_count - 2;
// Выводим количество файлов и подкаталогов
echo "Каталог $dirname содержит $file_count файлов
и $dir_count подкаталогов<br />";
// Устанавливаем указатель каталога в начало
$cat->rewind();
// Читаем содержимое каталога
while (($file = $cat->read()) !== false) {
if ($file != '.' && $file != '..') {
echo $file . '<br />';
}
}
// Закрываем каталог
$cat->close();