- Timestamp:
- 01/05/09 23:46:28 (2 years ago)
- Files:
-
- fDirectory.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
fDirectory.php
r448 r466 Hide Line Numbers 3 3 * Represents a directory on the filesystem, also provides static directory-related methods 4 4 * 5 * @copyright Copyright (c) 2007-200 8Will Bond5 * @copyright Copyright (c) 2007-2009 Will Bond 6 6 * @author Will Bond [wb] <will@flourishlib.com> 7 7 * @license http://flourishlib.com/license … … 10 10 * @link http://flourishlib.com/fDirectory 11 11 * 12 * @version 1.0.0b2 12 * @version 1.0.0b3 13 * @changes 1.0.0b3 Added the $regex_filter parameter to ::scan() and ::scanRecursive(), fixed bug in ::scanRecursive() [wb, 2009-01-05] 13 14 * @changes 1.0.0b2 Removed some unnecessary error suppresion operators [wb, 2008-12-11] 14 15 * @changes 1.0.0b The initial implementation [wb, 2007-12-21] … … 353 354 * Performs a [http://php.net/scandir scandir()] on a directory, removing the `.` and `..` entries 354 355 * 356 * @param string $regex_filter A PCRE to filter files/directories by path, directories can be detected by checking for a trailing / (even on Windows) 355 357 * @return array The fFile (or fImage) and fDirectory objects for the files/directories in this directory 356 358 */ 357 public function scan( )359 public function scan($regex_filter=NULL) 358 360 { 359 361 $this->tossIfException(); … … 364 366 foreach ($files as $file) { 365 367 $file = $this->directory . $file; 368 369 if ($regex_filter) { 370 $test_path = (is_dir($file)) ? $file . '/' : $file; 371 if (!preg_match($regex_filter, $test_path)) { 372 continue; 373 } 374 } 375 366 376 if (is_dir($file)) { 367 377 $objects[] = new fDirectory($file); … … 380 390 * Performs a **recursive** [http://php.net/scandir scandir()] on a directory, removing the `.` and `..` entries 381 391 * 392 * @param string $regex_filter A PCRE to filter files/directories by path, directories can be detected by checking for a trailing / (even on Windows) 382 393 * @return array The fFile and fDirectory objects for the files/directory (listed recursively) in this directory 383 394 */ 384 public function scanRecursive( )385 { 386 $this->tossIfException(); 387 388 $files = $this->scan();395 public function scanRecursive($regex_filter=NULL) 396 { 397 $this->tossIfException(); 398 399 $files = $this->scan(); 389 400 $objects = $files; 390 401 … … 392 403 for ($i=0; $i < $total_files; $i++) { 393 404 if ($files[$i] instanceof fDirectory) { 394 $objects = array_splice($objects, $i, 0, $files[$i]->scanRecursive()); 395 } 405 array_splice($objects, $i+1, 0, $files[$i]->scanRecursive()); 406 } 407 } 408 409 if ($regex_filter) { 410 $new_objects = array(); 411 foreach ($objects as $object) { 412 $test_path = ($object instanceof fDirectory) ? substr($object->getPath(), 0, -1) . '/' : $object->getPath(); 413 if (!preg_match($regex_filter, $test_path)) { 414 continue; 415 } 416 $new_objects[] = $object; 417 } 418 $objects = $new_objects; 396 419 } 397 420 … … 416 439 417 440 /** 418 * Copyright (c) 2007-200 8Will Bond <will@flourishlib.com>441 * Copyright (c) 2007-2009 Will Bond <will@flourishlib.com> 419 442 * 420 443 * Permission is hereby granted, free of charge, to any person obtaining a copy
