2021-03-25 11:44:17
شمارش فایلهای یک پوشه با php
با کد زیر میتونید یه خروجی داشته باشید که فایلهای پوشه دلخواهتون رو براتون بشماره.
function count_files($path) {
// (Ensure that the path contains an ending slash)
$file_count = 0;
$dir_handle = opendir($path);
if (!$dir_handle) return -1;
while ($file = readdir($dir_handle)) {
if ($file == '.' || $file == '..') continue;
if (is_dir($path . $file)){
$file_count += count_files($path . $file . DIRECTORY_SEPARATOR);
} else {
$file_count++; // increase file count
}}
closedir($dir_handle);
return $file_count;
}
echo count_files('d:\\BackFiles');
function count_files($path) {
// (Ensure that the path contains an ending slash)
$file_count = 0;
$dir_handle = opendir($path);
if (!$dir_handle) return -1;
while ($file = readdir($dir_handle)) {
if ($file == '.' || $file == '..') continue;
if (is_dir($path . $file)){
$file_count += count_files($path . $file . DIRECTORY_SEPARATOR);
} else {
$file_count++; // increase file count
}}
closedir($dir_handle);
return $file_count;
}
echo count_files('d:\\BackFiles');
#درخواستی
@BotSorce
1.6K views08:44