Posted By

fugue on 06/18/07


Tagged

scandir


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

carlosabargues
cro1979


Scandir


 / Published in: PHP
 

PHP4 replacement for the PHP5 function scandir. Parameters are $dir for the directory to be scanned, $filter to filter results, and $sort for a sorted array (0 = regular, 1 = reverse).

  1. function scandir ($dir = './', $filter = "", $sort = 0) {
  2. $dir_open = @ opendir($dir);
  3. if (! $dir_open)
  4. return false;
  5. while (($dir_content = readdir($dir_open)) !== false) {
  6. if (preg_match("/" . $filter . "/", $dir_content)) {
  7. $files[] = $dir_content;
  8. }
  9. }
  10. if (count($files) > 0) {
  11. if ($sort == 1)
  12. rsort($files, SORT_STRING);
  13. else
  14. sort($files, SORT_STRING);
  15. }
  16.  
  17. return $files;
  18. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: renoinn on June 18, 2007

thx for nice code

Posted By: renoinn on June 18, 2007

thx for nice code

You need to login to post a comment.