/** */ public function rewind() { parent::rewind(); while ($this->isDot()) { $this->next(); } }
/** * Rewinds the cache entry iterator to the first element * * @return void * @api */ public function rewind() { if ($this->cacheFilesIterator === null) { $this->cacheFilesIterator = new \DirectoryIterator($this->cacheDirectory); } $this->cacheFilesIterator->rewind(); while (substr($this->cacheFilesIterator->getFilename(), 0, 1) === '.' && $this->cacheFilesIterator->valid()) { $this->cacheFilesIterator->next(); } }
/** * Returns the available languages for this documentation format * * @return array Array of string language codes * @api */ public function getAvailableLanguages() { $languages = array(); $languagesDirectoryIterator = new \DirectoryIterator($this->formatPath); $languagesDirectoryIterator->rewind(); while ($languagesDirectoryIterator->valid()) { $filename = $languagesDirectoryIterator->getFilename(); if ($filename[0] != '.' && $languagesDirectoryIterator->isDir()) { $language = $filename; $languages[] = $language; } $languagesDirectoryIterator->next(); } return $languages; }
/** * Returns the available documentation formats for this documentation * * @return array Array of \TYPO3\Flow\Package\DocumentationFormat * @api */ public function getDocumentationFormats() { $documentationFormats = array(); $documentationFormatsDirectoryIterator = new \DirectoryIterator($this->documentationPath); $documentationFormatsDirectoryIterator->rewind(); while ($documentationFormatsDirectoryIterator->valid()) { $filename = $documentationFormatsDirectoryIterator->getFilename(); if ($filename[0] != '.' && $documentationFormatsDirectoryIterator->isDir()) { $documentationFormat = new \TYPO3\Flow\Package\Documentation\Format($filename, $this->documentationPath . $filename . '/'); $documentationFormats[$filename] = $documentationFormat; } $documentationFormatsDirectoryIterator->next(); } return $documentationFormats; }
public static function delete($dir) { $dir = new DirectoryIterator($dir); foreach ($dir as $file) { if ($file->isDot()) { continue; } else { if ($file->isDir()) { self::delete($file->getRealPath()); } else { if ($file->isFile()) { unlink($file->getRealPath()); } } } } $dir->rewind(); rmdir($dir->getRealPath()); }
/** * scan folders recursive and returns all folders * @param string $directory * @param string exclude * @return array|string */ public function scanRecursiveDir($directory, $exclude = '') { try { $file = ''; $it = new DirectoryIterator($directory); for ($it->rewind(); $it->valid(); $it->next()) { if ($it->isDir() && !$it->isDot()) { if ($it->getFilename() == $exclude) { continue; } $file[] = $it->getFilename(); } } return $file; } catch (Exception $e) { $logger = new debug_logger(MP_LOG_DIR); $logger->log('error', 'php', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_VOID); } }
/** * Returns the available documentations for this package * * @return array Array of \TYPO3\Flow\Package\Documentation * @api */ public function getPackageDocumentations() { $documentations = array(); $documentationPath = $this->getDocumentationPath(); if (is_dir($documentationPath)) { $documentationsDirectoryIterator = new \DirectoryIterator($documentationPath); $documentationsDirectoryIterator->rewind(); while ($documentationsDirectoryIterator->valid()) { $filename = $documentationsDirectoryIterator->getFilename(); if ($filename[0] != '.' && $documentationsDirectoryIterator->isDir()) { $filename = $documentationsDirectoryIterator->getFilename(); $documentation = new Documentation($this, $filename, $documentationPath . $filename . '/'); $documentations[$filename] = $documentation; } $documentationsDirectoryIterator->next(); } } return $documentations; }
function rewind() { echo __METHOD__ . "\n"; parent::rewind(); }
public function rewind() { parent::rewind(); }
/** * ( excerpt from http://php.net/manual/en/filesystemiterator.rewind.php ) * * Rewinds the directory back to the start. * * @return mixed No value is returned. */ public function rewind() { parent::rewind(); $this->goPastDotsIfNeeded(); }
echo '<tr><td>isWritable()</td><td> '; var_dump($item->isWritable()); echo '</td></tr>'; echo '<tr><td>isReadable()</td><td> '; var_dump($item->isReadable()); echo '</td></tr>'; echo '<tr><td>isExecutable(</td><td> '; var_dump($item->isExecutable()); echo '</td></tr>'; echo '<tr><td>isFile()</td><td> '; var_dump($item->isFile()); echo '</td></tr>'; echo '<tr><td>isDir()</td><td> '; var_dump($item->isDir()); echo '</td></tr>'; echo '<tr><td>isLink()</td><td> '; var_dump($item->isLink()); echo '</td></tr>'; echo '<tr><td>getFileInfo()</td><td> '; var_dump($item->getFileInfo()); echo '</td></tr>'; echo '<tr><td>getPathInfo()</td><td> '; var_dump($item->getPathInfo()); echo '</td></tr>'; echo '<tr><td>openFile()</td><td> '; var_dump($item->openFile()); echo '</td></tr>'; echo '<tr><td>setFileClass()</td><td> '; var_dump($item->setFileClass()); echo '</td></tr>'; echo '<tr><td>setInfoClass()</td><td> '; var_dump($item->setInfoClass()); echo '</td></tr>';*/ } } echo '</table>'; // while 循环 $directoryIt->rewind(); while ($directoryIt->valid()) { // 过滤 . 和 .. if (!$directoryIt->isDot()) { echo $directoryIt->key(), '=>', $directoryIt->current(), '<br />'; } $directoryIt->next(); } // 获得该目录的所有文件和下级文件夹的文件 /*$rdIt = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('/data/www/yii2/learn/backend')); foreach ($rdIt AS $name => $object) { echo $object.'<br/>'; }*/ echo '----------------------------------- DirectoryIterator END ---------------------------------', '<br />'; echo '--------------------------------- SimpleXMLIterator START-----------------------------------', '<br />'; /**
$di->seek(2); $n = 0; while ($di->valid()) { $n++; $di->next(); } echo "With seek(2) we get {$n}\n"; $di->seek(0); $m = 0; while ($di->valid()) { $m++; $di->next(); } echo "With seek(0) we get {$m}\n"; $o = 0; $di->rewind(); while ($di->valid()) { $o++; $di->next(); } echo "Without seek we get {$o}\n"; $p = 0; $di->seek($o + 1); while ($di->valid()) { $p++; $di->next(); } var_dump($n !== $m, $m === $o, $p === 0); ?> ===DONE===
/** * Rewind the Iterator to the first resource. */ public function rewind() { $this->iterator->rewind(); }
/** * Returns the available documentation formats for this documentation * * @return array Array of \F3\FLOW3\Package\DocumentationFormat * @author Christopher Hlubek <*****@*****.**> * @api */ public function getDocumentationFormats() { $documentationFormats = array(); $documentationFormatsDirectoryIterator = new \DirectoryIterator($this->documentationPath); $documentationFormatsDirectoryIterator->rewind(); while ($documentationFormatsDirectoryIterator->valid()) { $filename = $documentationFormatsDirectoryIterator->getFilename(); if ($filename[0] != '.' && $documentationFormatsDirectoryIterator->isDir()) { $documentationFormat = $this->objectFactory->create('F3\\FLOW3\\Package\\Documentation\\Format', $filename, $this->documentationPath . $filename . '/'); $documentationFormats[$filename] = $documentationFormat; } $documentationFormatsDirectoryIterator->next(); } return $documentationFormats; }
$request = substr($_SERVER['REDIRECT_URL'],strlen($_SERVER['PHP_SELF'])-9); define('NUM_PER_PAGE',3); //need to sanatize preg_match("#page/([0-9]+)#",$request,$matches); $page = (int)$matches[1]; preg_match("#photo/([0-9A-Za-z-]+)#",$request,$matches); $requestedPhoto = $matches[1]; $photos = new DirectoryIterator('./photos'); $fileNames = $currentPageFiles = array(); $photos->rewind(); foreach($photos as $photo) { if(!$photo->isDot() && $photo->isFile()) { $numFiles++; $fileNames[] = $photo->getFilename(); } } $numPages = ceil($numFiles/NUM_PER_PAGE); if($requestedPhoto && in_array($requestedPhoto.'.jpg',$fileNames)) { $exif = exif_read_data('./photos/'.$requestedPhoto.'.jpg'); $currentPhoto = $exif; $currentPhoto['webHref'] = '/source/chapter7/browser/photos/'.$requestedPhoto.'.jpg'; $currentPage = ceil((array_search($requestedPhoto.'.jpg',$fileNames)+1)/NUM_PER_PAGE); $currentPageFiles = array_slice($fileNames,NUM_PER_PAGE*($currentPage-1),NUM_PER_PAGE);
/** * @param int $offset * @param int $limit * @param int|string|float $search * @return array */ protected function paginateFilesSearch($offset, $limit, $search) { $filei = 0; $listTotal = 0; $list = array(); if ($offset === 0) { $offset = -1; } else { $filei = 1; } $search = (string) $search; while (parent::valid() && $listTotal < $limit) { $current = parent::current(); if ($current->isFile() && stripos($current->getFilename(), $search) !== false && $filei++ > $offset) { $list[] = clone $current; $listTotal++; } parent::next(); } parent::rewind(); return $list; }
/** * scan folders recursive and returns all folders * @param string $directory * @param string exclude */ public function scanRecursiveDir($directory, $exclude = '') { try { $file = ''; $it = new DirectoryIterator($directory); for ($it->rewind(); $it->valid(); $it->next()) { if ($it->isDir() && !$it->isDot()) { if ($it->getFilename() == $exclude) { continue; } $file[] = $it->getFilename(); } } return $file; } catch (Exception $e) { $log = magixcjquery_error_log::getLog(); $log->logfile = M_TMP_DIR; $log->write('An error has occured', $e->getMessage(), $e->getLine()); die("Failed scan folders recursive"); } }