/** * Returns true if file is valid. * Valid Files: Directories and Files not beginning with a "." (dot). * * @todo make it more flexible to handle hidden dirs on demand etc, * win/*nix compat * * @return boolean if current file entry is vali */ public function valid() { if (parent::valid()) { if (parent::isDot() || parent::isDir() && strpos(parent::getFilename(), '.') === 0) { parent::next(); // zum nächsten eintrag hüpfen return $this->valid(); // nochmal prüfen } return true; } return false; }
/** * Recursive directory function. * * @param RecursiveDirectoryIterator $iterator */ protected function _recurseDirectory($iterator) { while ($iterator->valid()) { if ($iterator->isDir() && !$iterator->isDot()) { if ($iterator->hasChildren()) { $this->_recurseDirectory($iterator->getChildren()); } } elseif ($iterator->isFile()) { $path = $iterator->getPath() . '/' . $iterator->getFilename(); $pathinfo = pathinfo($path); if ($this->_isPhpFile($path)) { $this->addFile($path); } } $iterator->next(); } }
<?php $folder = $_POST['path']; $flags = FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS; $d_iterator = new RecursiveDirectoryIterator($folder, $flags); $directories = array(); foreach ($d_iterator as $file) { if ($d_iterator->isDir()) { $directories[] = $d_iterator->getFileName(); } } echo json_encode($directories);
$xmlForms = array("form" => array(), "resource" => array()); if ($info->isDir()) { $iterator = new RecursiveDirectoryIterator($formImportDir); while ($iterator->valid()) { if ($iterator->isFile()) { $ext = pathinfo($iterator->getPathname(), PATHINFO_EXTENSION); if ($ext == "xml") { // echo $prefix,$j," import ",$dirIterator->getPathname(), "<br>\n"; $xmlForms["form"][$iterator->getFilename()] = $iterator->getPathname(); } else { $filepath = preg_replace("/" . preg_replace("/\\//", "\\\\/", HEURIST_UPLOAD_DIR) . "/", "/", $iterator->getPathname()); // echo $prefix,$j," resource ".$dirIterator->getFilename()." has path ".$filepath, "<br>\n"; $xmlForms["resource"][$iterator->getFilename()] = $filepath; } } else { if ($iterator->isDir() && $iterator->hasChildren(false)) { // echo $i,pathinfo($iterator->getPathname(),PATHINFO_FILENAME), "<br>\n"; processChildDir($iterator->getChildren(), $i . "-"); } } $iterator->next(); $i++; } } else { echo "something is wrong"; } foreach ($xmlForms["form"] as $filename => $path) { list($rtyName, $headers, $row) = parseImportForm($filename, $xmlForms["resource"]); $rtyName = "" . $rtyName; if (!$rtyName) { continue;
/** * * Recursively iterates through a directory looking for class files. * * Skips CVS directories, and all files and dirs not starting with * a capital letter (such as dot-files). * * @param RecursiveDirectoryIterator $iter Directory iterator. * * @return void * */ protected function _fetch(RecursiveDirectoryIterator $iter) { for ($iter->rewind(); $iter->valid(); $iter->next()) { // preliminaries $path = $iter->current()->getPathname(); $file = basename($path); $capital = ctype_alpha($file[0]) && $file == ucfirst($file); $phpfile = strripos($file, '.php'); // check for valid class files if ($iter->isDot() || !$capital) { // skip dot-files (including dot-file directories), as // well as files/dirs not starting with a capital letter continue; } elseif ($iter->isDir() && $file == 'CVS') { // skip CVS directories continue; } elseif ($iter->isDir() && $iter->hasChildren()) { // descend into child directories $this->_fetch($iter->getChildren()); } elseif ($iter->isFile() && $phpfile) { // map the .php file to a class name $len = strlen($this->_base); $class = substr($path, $len, -4); // drops .php $class = str_replace(DIRECTORY_SEPARATOR, '_', $class); $this->_map[$class] = $path; } } }
function valid() { if (parent::valid()) { if (!parent::isDir() || parent::isDot()) { parent::next(); return $this->valid(); } return TRUE; } return FALSE; }
/** * Force deletion on a cached resource. * * @param {string} $key Identifier of target cache. * @param {?string} $hash Target revision to delete, all revisions will be deleted if omitted. */ public static function delete($key, $hash = '*') { $res = self::resolve($key, $hash); // Skip the delete if nothing is found. if ($res === null) { return; } if ($res->isFile()) { // Remove target revision(s). if (!$res->isWritable()) { Log::warning('Target file is not writable, deletion skipped.'); } else { $path = $res->getRealPath(); unlink($path); $path = dirname($path); // Remove the directory if empty. $res = new \RecursiveDirectoryIterator($path, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS); if ($res->isDir() && !$res->hasChildren()) { rmdir($path); } } } else { if ($res->isDir()) { $cacheDirectory = $res->getRealPath(); foreach ($res as $file) { if ($file->isFile()) { unlink($file->getRealPath()); } else { if ($file->isDir()) { rmdir($file->getRealPath()); } } } rmdir($cacheDirectory); } } }