Posted By

koncept on 12/26/09


Tagged

search index php5 profile recursion mode stat


Versions (?)

PHP5 fast recursive directory listing, profiling items by type


 / Published in: PHP
 

  1. <?php
  2. /**
  3.  * PHP5 - Fast, recursive, directory profiler
  4.  * @param string $dir Path to a readable directory path
  5.  * @version 1.0
  6.  */
  7. function profile( $dir ) {
  8. static $info = array();
  9. if( is_dir( $dir = rtrim( $dir, "/\\" ) ) ) {
  10. foreach( scandir( $dir) as $item ) {
  11. if( $item != "." && $item != ".." ) {
  12. $info['all'][] = $absPath = $dir . DIRECTORY_SEPARATOR . $item;
  13. $stat = stat( $absPath );
  14. switch( $stat['mode'] & 0170000 ) {
  15. case 0010000: $info['files'][] = $absPath; break;
  16. case 0040000: $info['directories'][] = $absPath; profile( $absPath ); break;
  17. case 0120000: $info['links'][] = $absPath; break;
  18. case 0140000: $info['sockets'][] = $absPath; break;
  19. case 0010000: $info['pipes'][] = $absPath; break;
  20. }
  21. }
  22. }
  23. }
  24. return $info;
  25. }
  26. ?>

Report this snippet  

You need to login to post a comment.