Omirion Posted January 27, 2010 Share Posted January 27, 2010 Hello, Is there a way for php 5.2.5 to return the number of files in a folder? Link to comment https://forums.phpfreaks.com/topic/189994-get-number-of-files-in-a-folder/ Share on other sites More sharing options...
jim_de_bo Posted January 27, 2010 Share Posted January 27, 2010 I have used this before...I'm sure there are other ways. $dir = '/tmp'; $files1 = scandir($dir); $number = count($files1); echo $number; Link to comment https://forums.phpfreaks.com/topic/189994-get-number-of-files-in-a-folder/#findComment-1002394 Share on other sites More sharing options...
gwolgamott Posted January 27, 2010 Share Posted January 27, 2010 By using scandir built in function. Put the data from that into an array then counting the elements of the array. <?php $bob = scandir("images/"); $count = count($bob); echo $count; ?> Of course you will want to sort out of the array the directory listing as well. $bob = scandir("images/"); $count = count($bob); for($i = 0; $i < $count; $i++) // Loops through $bob { if(is_file($bob[$i])) { array_push($bob_2,bob[$i]); // adds an array element to $bob_2 only if not a folder and is a file } } $count = count($bob_2); echo $count; http://www.w3schools.com/php/func_directory_scandir.asp Link to comment https://forums.phpfreaks.com/topic/189994-get-number-of-files-in-a-folder/#findComment-1002409 Share on other sites More sharing options...
Omirion Posted January 27, 2010 Author Share Posted January 27, 2010 Thank you, This works for me Link to comment https://forums.phpfreaks.com/topic/189994-get-number-of-files-in-a-folder/#findComment-1002421 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.