public static function index(Path $path, $levels = null, &$count = 0) { printf("Indexing: %s\n", $path->getRelative()); if (preg_match("/^\\.in\\./", $path->getFilename())) { return; } try { $record = $path->loadRecord(); // if this path does not exist, and we have a record then delete it if (!$path->exists()) { if ($record) { $record->delete(); } return; } if (!$record) { // none exists, create it $path->loadCreateRecord(); $count++; } else { // it exists, check if it needs updating if ($record->checkUpdate($path)) { $count++; } } // index children if ($levels > 0 || $levels === null) { if ($levels !== null) { $levels--; } if ($path->isDir()) { $children = $path->getChildren(); foreach ($children as $child) { self::index($child, $levels, $count); } } } } catch (Exception $e) { print (string) $e; Log::error($e, array('path' => $path->getRelative())); } }
public function exists() { return Path::exists($this->path); }
/** * Returns content of directory. * * If $split == true, Path::listdir returns flat array with mixed * files and directories. * Otherwise, return 2-element associative array, with keys: 'files' * and 'dirs'. * * Return doesn't include 'dots' ('.' and '..'). * * @param string $dir directory to scan * @param string $order Path::SORT_ASC or Path::SORT_DESC * @param boolean $split * * @return array * @throws CENotFound ({@link CENotFound description}) * * @access public */ public static function listdir($dir, $order = self::SORT_ASC, $split = false) { $dir = Path::real($dir); if (!Path::exists($dir)) { throw new CENotFound(sprintf('Directory "%s" not found.', $dir)); } $files = array(); $dirs = array(); $d = dir($dir); while (false !== ($obj = $d->read())) { if (in_array($obj, array('.', '..'))) { continue; } $path = Path::join($dir, $obj); if (is_link($path)) { $path = readlink($path); $obj = basename($path); } if (is_file($path)) { $files[] = $obj; } else { if (is_dir($path)) { $dirs[] = $obj; } } } if (!$split) { $ret = array_merge($files, $dirs); switch ($order) { case self::SORT_ASC: sort($ret, SORT_STRING); break; case self::SORT_DESC: rsort($ret, SORT_STRING); break; } } else { switch ($order) { case self::SORT_ASC: sort($files); sort($dirs); break; case self::SORT_DESC: rsort($files); rsort($dirs); break; } $ret = array('files' => $files, 'dirs' => $dirs); } return $ret; }