本文整理汇总了PHP中RecursiveDirectoryIterator类的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveDirectoryIterator类的具体用法?PHP RecursiveDirectoryIterator怎么用?PHP RecursiveDirectoryIterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RecursiveDirectoryIterator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: zipData
function zipData($source, $destination)
{
if (extension_loaded('zip')) {
if (file_exists($source)) {
$zip = new ZipArchive();
if ($zip->open($destination, ZIPARCHIVE::CREATE)) {
$source = realpath($source);
if (is_dir($source)) {
$iterator = new RecursiveDirectoryIterator($source);
// skip dot files while iterating
$iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file) {
$file = realpath($file);
if (is_dir($file)) {
$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
} else {
if (is_file($file)) {
$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
}
}
}
} else {
if (is_file($source)) {
$zip->addFromString(basename($source), file_get_contents($source));
}
}
}
echo $destination . ' zip: successfully...';
echo "\n";
return $zip->close();
}
}
return false;
}
开发者ID:phn007,项目名称:BuildHtml,代码行数:35,代码来源:zip.php
示例2: index
public function index()
{
parent::index();
$album = empty($this->parameters) ? "" : array_shift($this->parameters);
$dir = new \RecursiveDirectoryIterator(dirname(__DIR__) . $this->basedir . $album);
if (empty($album)) {
$albums = array();
foreach ($dir as $name => $object) {
$shortname = basename($name);
if ($shortname != ".." && $shortname != ".") {
$temp_album = new \DirectoryIterator($name);
foreach ($temp_album as $img) {
if ($img->isFile()) {
break;
}
}
$albums[$dir->getCTime()] = array("name" => $shortname, "image" => $this->basedir . $shortname . "/" . $img, "link" => "/fotos/index/" . $shortname);
}
}
ksort($albums);
$this->context["albums"] = $albums;
} else {
$pictures = array();
foreach ($dir as $image) {
$shortname = basename($image);
if ($shortname != ".." && $shortname != ".") {
$pictures[] = $this->basedir . $album . "/" . $shortname;
}
}
$this->context["pictures"] = $pictures;
$this->context["album"] = $album;
}
}
开发者ID:arnedesmedt,项目名称:tuinhier-ichtegem,代码行数:33,代码来源:fotosController.php
示例3: getCallableModules
/**
* get callable module list
*
* @return array
*/
public function getCallableModules()
{
$dirIterator = new \RecursiveDirectoryIterator($this->path, \FilesystemIterator::NEW_CURRENT_AND_KEY | \FilesystemIterator::SKIP_DOTS);
$modules = array();
foreach ($dirIterator as $k => $v) {
$doVotedModule = false;
if ($dirIterator->hasChildren()) {
foreach ($dirIterator->getChildren() as $key => $value) {
$entension = $value->getExtension();
if (!$entension || 'php' !== $entension) {
continue;
}
$fileBasename = $value->getBasename('.php');
$module_to_be = $v->getBasename();
$expectedClassName = $this->baseNamespace . NAMESPACE_SEPARATOR . $module_to_be . NAMESPACE_SEPARATOR . $fileBasename;
Loader::getInstance()->import($value->__toString());
if (!class_exists($expectedClassName, false)) {
// not a standard class file!
continue;
}
if (!$doVotedModule) {
$modules[] = $module_to_be;
$doVotedModule = true;
}
}
}
}
return $modules;
}
开发者ID:TF-Joynic,项目名称:Hydrogen,代码行数:34,代码来源:ConsoleHelper.php
示例4: listPosts
public function listPosts()
{
$path = null;
$timestamp = null;
$dirname = $this->settings->posts_dir;
$dir = new \RecursiveDirectoryIterator($dirname);
$dir->setFlags(\RecursiveDirectoryIterator::SKIP_DOTS);
ob_start();
?>
<div class="row">
<table class="post-table">
<tr>
<th>Name</th>
<th>Date created</th>
</tr>
<?php
foreach ($dir as $fileinfo) {
if ($fileinfo->getMTime() > $timestamp) {
// current file has been modified more recently
// than any other file we've checked until now
$path = $fileinfo->getFilename();
$modified = $fileinfo->getMTime();
$created = $fileinfo->getCTime();
$linkUrl = preg_replace('/\\.[^.\\s]{1,4}$/', '', $path);
echo "<tr><td><a href='?action=edit&post=" . $linkUrl . "'>" . $path . "</a></td>";
echo "<td>" . date("F d Y H:i:s.", $created) . "</td></tr>";
}
}
?>
</table>
</div>
<style>
.post-table {
width: 80%;
margin: 50px auto;
text-align: center;
border: solid 1px #ddd;
}
.post-table th {
font-weight: bold;
}
.post-table th,
.post-table td {
text-align: left;
padding: 5px;
border: solid 1px #ddd;
}
</style>
<?php
return ob_get_clean();
}
开发者ID:dangerdan,项目名称:Dropplets2,代码行数:58,代码来源:PostManager.php
示例5: show_maps
function show_maps()
{
$maps = array();
$it = new RecursiveDirectoryIterator('../maps');
foreach (new RecursiveIteratorIterator($it) as $file) {
if (!$it->isDot()) {
array_push($maps, basename($file));
}
}
echo json_encode($maps);
}
开发者ID:kaizensoze,项目名称:chips-challenge,代码行数:11,代码来源:chip.php
示例6: from
/**
* Create Pages object instance from path
*
* @param string $path
* @param array|callable $filter
* @param string $class
* @return \cms\Pages
*/
public static function from($path, $filter = ['index', '404'], $class = Page::class)
{
$iterator = new \RecursiveDirectoryIterator(realpath($path), \RecursiveDirectoryIterator::SKIP_DOTS);
if (class_exists($class)) {
$iterator->setInfoClass($class);
}
$filter = is_callable($filter) ? $filter : function (Page $item) use($filter) {
return $item->isValid((array) $filter);
};
return new self(new \RecursiveCallbackFilterIterator($iterator, $filter));
}
开发者ID:austinvernsonger,项目名称:cms,代码行数:19,代码来源:Pages.php
示例7: routesInDirectory
function routesInDirectory($app = '')
{
$routeDir = app_path('Http/Routes/' . $app . ($app !== '' ? '/' : NULL));
$iterator = new RecursiveDirectoryIterator($routeDir);
$iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
foreach ($iterator as $route) {
$isDotFile = strpos($route->getFilename(), '.') === 0;
if (!$isDotFile && !$route->isDir()) {
require $routeDir . $route->getFilename();
}
}
}
开发者ID:RoryStolzenberg,项目名称:spacexstats,代码行数:12,代码来源:routes.php
示例8: getImagePaths
/**
* A function to (optionally) recursive through a root directory,
* retrieving image paths
*
* @param $folder
* The root folder to start the scanning
* @param $enable_chidren
* Boolean value to enable scanning through child folders, default to false
*
* @return
* An array of image paths
*
* @todo
* Use more robust php recursive directory search options
*/
static function getImagePaths($folder, $enable_chidren = FALSE)
{
$image_array = array();
$iterator = new RecursiveDirectoryIterator($folder);
$image_array = array_merge($image_array, VSMGFileHelper::getDirectoryImages($folder));
if ($enable_chidren) {
foreach ($iterator as $file) {
if (is_dir($file) && !$iterator->isDot()) {
// echo "VSMGFileHelper::getImagePaths DIR: $file\n";
$image_array = array_merge($image_array, VSMGFileHelper::getDirectoryImages($file));
}
}
}
return $image_array;
}
开发者ID:niallcreech,项目名称:vsmg,代码行数:30,代码来源:VSMGFileHelper.php
示例9: _deleteFolder
/**
* deletes a folder recursively
*
* @param string $path the folder to delete
*
* @since 1.0
*/
protected static function _deleteFolder($path)
{
/**
* @var \SplFileInfo $item
*/
$dir = new \RecursiveDirectoryIterator($path);
while ($dir->valid()) {
$item = $dir->current();
if (!in_array($item->getFilename(), array('.', '..'))) {
$isFile = $item->isFile();
$isFile ? unlink($item->getRealPath()) : self::_deleteFolder($item->getRealPath());
}
$dir->next();
}
rmdir($path);
}
开发者ID:elibyy,项目名称:zip,代码行数:23,代码来源:TestCase.php
示例10: getChildren
/** Override of getChildren in \RecursiveDirectoryIterator, to skip directories with insufficient rights to access
* @internal
*/
function getChildren()
{
try {
return parent::getChildren();
} catch (\UnexpectedValueException $e) {
return new \RecursiveArrayIterator(array());
}
}
开发者ID:zhengxiexie,项目名称:wordpress,代码行数:11,代码来源:IgnorantRecursiveDirectoryIterator.php
示例11: import
/**
* import
*
* @param string $tsvDirPath
* @access public
* @return void
*/
public function import($tsvDirPath = null)
{
if (is_null($tsvDirPath)) {
$tsvDirPath = realpath(__DIR__ . '/../../../../../../masterData');
}
$iterator = new \RecursiveDirectoryIterator($tsvDirPath);
foreach ($iterator as $file) {
if (!$iterator->hasChildren()) {
continue;
}
$databaseName = $file->getFileName();
$con = $this->getConnection($databaseName);
$con->exec('set foreign_key_checks = 0');
$this->importFromTsvInDir($iterator->getChildren(), $con);
$con->exec('set foreign_key_checks = 1');
}
}
开发者ID:magical-yuri,项目名称:magical-girl,代码行数:24,代码来源:MasterDBImporter.php
示例12: getOutdatedFiles
/**
* Retrieves old CSS files and list them
*
* @param $ttl int
* @return array
*/
protected function getOutdatedFiles($ttl)
{
$outdated = array();
$time = time();
$dir = new RecursiveDirectoryIterator($this->configuration->getUploadDir());
$dir->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
/*
* Collecting CSS files
*/
$files = new RegexIterator(new RecursiveIteratorIterator($dir), '#.css#U', RecursiveRegexIterator::ALL_MATCHES);
/*
* Checking expiry
*/
foreach ($files as $filepath => $match) {
filemtime($filepath) + $ttl < $time ? array_push($outdated, $filepath) : null;
}
return $outdated;
}
开发者ID:leotaillard,项目名称:btws2016,代码行数:24,代码来源:Garbagecollector.class.php
示例13: __construct
public function __construct(array $sources)
{
foreach ($sources as $source) {
if ($source instanceof \SplFileInfo) {
$this->children[] = $source;
} elseif (is_string($source) && ($source = realpath($source))) {
if (is_file($source)) {
$child = new SourceFileInfo($source);
$child->setInfoClass(SourceFileInfo::class);
$this->children[] = $child;
} elseif (is_dir($source)) {
$child = new \RecursiveDirectoryIterator($source);
$child->setInfoClass(SourceFileInfo::class);
$this->children[] = $child;
}
}
}
}
开发者ID:clockworkgeek,项目名称:magei18n,代码行数:18,代码来源:RecursiveSourcesIterator.php
示例14: zipData
public function zipData($source, $destination)
{
global $Language;
$archiveName = 'backup-' . time() . '.zip';
// Archive name
if (extension_loaded('zip')) {
if (file_exists($source)) {
$zip = new ZipArchive();
if ($zip->open($destination, ZIPARCHIVE::CREATE)) {
$source = realpath($source);
if (is_dir($source)) {
$iterator = new RecursiveDirectoryIterator($source);
// skip dot files while iterating
$iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file) {
$file = realpath($file);
if (is_dir($file)) {
$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
} else {
if (is_file($file)) {
$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
}
}
}
} else {
if (is_file($source)) {
$zip->addFromString(basename($source), file_get_contents($source));
}
}
}
if (!$zip->close()) {
Alert::set($Language->get("There was a problem writing the ZIP archive."));
Redirect::page('admin', 'configure-plugin/pluginBackup');
} else {
Alert::set($Language->get("Successfully created the ZIP Archive!"));
Redirect::page('admin', 'configure-plugin/pluginBackup');
}
// close the zip file
$zip->close();
}
}
return false;
}
开发者ID:joryphillips,项目名称:bludit-plugins,代码行数:44,代码来源:plugin.php
示例15: make
/**
* @param string $dir
* @return FileIndex
*/
public static function make($dir)
{
$dirIterator = new \RecursiveDirectoryIterator($dir);
$dirIterator->setFlags(\RecursiveDirectoryIterator::SKIP_DOTS);
$recursiveIterator = new \RecursiveIteratorIterator($dirIterator, \RecursiveIteratorIterator::SELF_FIRST);
$results = array();
foreach ($recursiveIterator as $file) {
/** @var \SplFileInfo $file */
// ignore non files
if (!$file->isFile()) {
continue;
}
// ignore non php files
$ext = strtolower($file->getExtension());
if ($ext !== 'php') {
continue;
}
$results[] = $file->getPathname();
}
return new self($results);
}
开发者ID:superbalist,项目名称:php-money,代码行数:25,代码来源:FileIndex.php
示例16: folder_files
function folder_files($path)
{
$iterator = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
$files = [];
foreach ($iterator as $item) {
if ($item->isDir()) {
continue;
}
$files[] = $iterator->getPathName();
}
return $files;
}
开发者ID:philippgerard,项目名称:slayer,代码行数:12,代码来源:paths.php
示例17: cmd_artifact
public function cmd_artifact(array $params = array())
{
\System\Directory::check(BASE_DIR . static::DIR_PACKAGES);
$target = BASE_DIR . static::DIR_PACKAGES . '/artifact.tar';
$result = $target . '.gz';
if (isset($params[0])) {
$target = $params[0];
}
if (file_exists($target)) {
unlink($target);
}
if (file_exists($result)) {
unlink($result);
}
$iter = new \RecursiveDirectoryIterator(BASE_DIR);
$iter->setFlags(\FileSystemIterator::SKIP_DOTS);
$iter = new ProjectDirectoryRecursiveIterator($iter);
$iter = new \RecursiveIteratorIterator($iter);
$archive = new \PharData($target);
$archive->buildFromIterator($iter, BASE_DIR);
$archive->compress(\Phar::GZ);
unlink($target);
}
开发者ID:just-paja,项目名称:fudjan,代码行数:23,代码来源:package.php
示例18: getExamples
/**
* Data provider for testExamples method.
*
* Assumes that an `examples` directory exists inside parent directory.
* This examples directory should contain any number of subdirectories, each of which contains
* three files: one Mustache class (.php), one Mustache template (.mustache), and one output file
* (.txt).
*
* This whole mess will be refined later to be more intuitive and less prescriptive, but it'll
* do for now. Especially since it means we can have unit tests :)
*
* @access public
* @return array
*/
public function getExamples()
{
$basedir = dirname(__FILE__) . '/../examples/';
$ret = array();
$files = new RecursiveDirectoryIterator($basedir);
while ($files->valid()) {
if ($files->hasChildren() && ($children = $files->getChildren())) {
$example = $files->getSubPathname();
$class = null;
$template = null;
$output = null;
foreach ($children as $file) {
if (!$file->isFile()) {
continue;
}
$filename = $file->getPathInfo();
$info = pathinfo($filename);
switch ($info['extension']) {
case 'php':
$class = $info['filename'];
include_once $filename;
break;
case 'mustache':
$template = file_get_contents($filename);
break;
case 'txt':
$output = file_get_contents($filename);
break;
}
}
$ret[$example] = array($class, $template, $output);
}
$files->next();
}
return $ret;
}
开发者ID:kennethreitz-archive,项目名称:wp-mustache,代码行数:50,代码来源:MustacheTest.php
示例19: iterateFiles
/**
* Not using recursiveDirectoryIterator to savely ignore unreadable directories
*
* @param RecursiveDirectoryIterator $iter
*/
protected function iterateFiles(RecursiveDirectoryIterator $iter)
{
foreach ($iter as $file) {
if (!is_readable($file)) {
continue;
} else {
if (!$iter->isDot()) {
if (is_file((string) $file)) {
if (!$this->isIgnored($file) && !$this->isIgnoredDirectory($file)) {
$this->results[] = new Robo47_DirectoryHasher_Result_File($file);
}
} else {
if (is_dir($file)) {
$this->iterateFiles(new RecursiveDirectoryIterator((string) $file));
}
}
}
}
}
}
开发者ID:robo47,项目名称:Robo47_DirectoryHasher,代码行数:25,代码来源:Directory.php
示例20: load_tests
private function load_tests(RecursiveDirectoryIterator $dir)
{
while ($dir->valid()) {
$current = $dir->current();
if ($dir->isFile() && preg_match("/(.)Test\\.php\$/", $current->getFilename(), $matches)) {
// XXX: handle errors
include $current->getPathname();
$x = explode('.', $current->getFilename());
$class = $x[0];
$rclass = new ReflectionClass($class);
if ($rclass->getParentClass()->getName() == 'UnitTest') {
$this->cases[] = $rclass;
}
} elseif ($dir->hasChildren() && preg_match("/^\\./", $current->getFilename(), $matches) == 0) {
$this->load_tests($dir->getChildren());
}
$dir->next();
}
}
开发者ID:BackupTheBerlios,项目名称:medick-svn,代码行数:19,代码来源:TestRunner.php
注:本文中的RecursiveDirectoryIterator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论