本文整理汇总了PHP中RecursiveIteratorIterator::isDir方法的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveIteratorIterator::isDir方法的具体用法?PHP RecursiveIteratorIterator::isDir怎么用?PHP RecursiveIteratorIterator::isDir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RecursiveIteratorIterator
的用法示例。
在下文中一共展示了RecursiveIteratorIterator::isDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rmdir
/**
* Remove recursively the directory named by dirname.
*
* @param string $dirname Path to the directory
* @param boolean $followLinks Removes symbolic links if set to true
* @return boolean True if success otherwise false
* @throws Exception When the directory does not exist or permission denied
*/
public static function rmdir($dirname, $followLinks = false)
{
if (!is_dir($dirname) && !is_link($dirname)) {
throw new Exception(sprintf('Directory %s does not exist', $dirname));
}
if (!is_writable($dirname)) {
throw new Exception('You do not have renaming permissions');
}
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirname), RecursiveIteratorIterator::CHILD_FIRST);
while ($iterator->valid()) {
if (!$iterator->isDot()) {
if (!$iterator->isWritable()) {
throw new Exception(sprintf('Permission denied for %s', $iterator->getPathName()));
}
if ($iterator->isLink() && false === (bool) $followLinks) {
$iterator->next();
continue;
}
if ($iterator->isFile()) {
unlink($iterator->getPathName());
} else {
if ($iterator->isDir()) {
rmdir($iterator->getPathName());
}
}
}
$iterator->next();
}
unset($iterator);
return rmdir($dirname);
}
示例2: recursive_rmdir
private function recursive_rmdir($dirname, $followLinks = false)
{
if (is_dir($dirname) && !is_link($dirname)) {
if (!is_writable($dirname)) {
throw new Exception('You do not have renaming permissions!');
}
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirname), RecursiveIteratorIterator::CHILD_FIRST);
while ($iterator->valid()) {
if (!$iterator->isDot()) {
if (!$iterator->isWritable()) {
throw new Exception(sprintf('Permission Denied: %s.', $iterator->getPathName()));
}
if ($iterator->isLink() && false === (bool) $followLinks) {
$iterator->next();
}
if ($iterator->isFile()) {
unlink($iterator->getPathName());
} else {
if ($iterator->isDir()) {
rmdir($iterator->getPathName());
}
}
}
$iterator->next();
}
unset($iterator);
// Fix for Windows.
return rmdir($dirname);
} else {
throw new Exception(sprintf('Directory %s does not exist!', $dirname));
}
}
示例3: execute
/**
* Do the job.
* Throw exceptions on errors (the job will be retried).
*/
public function execute()
{
global $CFG;
$tmpdir = $CFG->tempdir;
// Default to last weeks time.
$time = strtotime('-1 week');
$dir = new \RecursiveDirectoryIterator($tmpdir);
// Show all child nodes prior to their parent.
$iter = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::CHILD_FIRST);
for ($iter->rewind(); $iter->valid(); $iter->next()) {
$node = $iter->getRealPath();
if (!is_readable($node)) {
continue;
}
// Check if file or directory is older than the given time.
if ($iter->getMTime() < $time) {
if ($iter->isDir() && !$iter->isDot()) {
// Don't attempt to delete the directory if it isn't empty.
if (!glob($node . DIRECTORY_SEPARATOR . '*')) {
if (@rmdir($node) === false) {
mtrace("Failed removing directory '{$node}'.");
}
}
}
if ($iter->isFile()) {
if (@unlink($node) === false) {
mtrace("Failed removing file '{$node}'.");
}
}
}
}
}
示例4: buildArray
public function buildArray()
{
$directory = new \RecursiveDirectoryIterator('assets');
$iterator = new \RecursiveIteratorIterator($directory, \RecursiveIteratorIterator::CHILD_FIRST);
$tree = [];
foreach ($iterator as $info) {
//if (in_array($info->getFilename(), ['.', '..'])) continue;
if ($iterator->getDepth() >= 2 || !$iterator->isDir() || $iterator->isDot()) {
continue;
}
if ($iterator->getDepth() == 1) {
$path = $info->isDir() ? [$iterator->getDepth() - 1 => $info->getFilename()] : [$info->getFilename()];
} else {
$path = $info->isDir() ? [$info->getFilename() => []] : [$info->getFilename()];
}
for ($depth = $iterator->getDepth() - 1; $depth >= 0; $depth--) {
$path = [$iterator->getSubIterator($depth)->current()->getFilename() => $path];
}
$tree = array_merge_recursive($tree, $path);
}
$data = array();
foreach ($tree as $category => $children) {
foreach ($children as $index => $value) {
$data[$category][] = $value;
}
}
foreach ($data as $category => $children) {
$parentId = $this->addEntry($category, '0');
foreach ($children as $index => $value) {
$this->addEntry($value, $parentId);
}
}
return $data;
}
示例5: findDirectories
public static function findDirectories($rootDir, $multiMap = true)
{
if (!is_dir($rootDir)) {
throw new \LogicException($rootDir . ' is not a directory');
}
$elements = array();
$d = @dir($rootDir);
if (!$d) {
throw new \LogicException('Directory is not readable');
}
$dirs = array();
$it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($rootDir, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
while ($it->valid()) {
if (!$it->isDir()) {
$it->next();
} else {
$cur = $it->current();
if ($cur->isDir()) {
if ($multiMap) {
$dirs[$cur->getPath()][] = $cur->getFilename();
} else {
$dirs[] = $cur->getPath();
}
}
$it->next();
}
}
return $dirs;
}
示例6: countThemePages
protected function countThemePages($path)
{
$result = 0;
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
$it->setMaxDepth(1);
while ($it->valid()) {
if (!$it->isDot() && !$it->isDir() && $it->getExtension() == 'htm') {
$result++;
}
$it->next();
}
return $result;
}
示例7: execute
/**
* Do the job.
* Throw exceptions on errors (the job will be retried).
*/
public function execute()
{
global $CFG;
$tmpdir = $CFG->tempdir;
// Default to last weeks time.
$time = time() - $CFG->tempdatafoldercleanup * 3600;
$dir = new \RecursiveDirectoryIterator($tmpdir);
// Show all child nodes prior to their parent.
$iter = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::CHILD_FIRST);
// An array of the full path (key) and date last modified.
$modifieddateobject = array();
// Get the time modified for each directory node. Nodes will be updated
// once a file is deleted, so we need a list of the original values.
for ($iter->rewind(); $iter->valid(); $iter->next()) {
$node = $iter->getRealPath();
if (!is_readable($node)) {
continue;
}
$modifieddateobject[$node] = $iter->getMTime();
}
// Now loop through again and remove old files and directories.
for ($iter->rewind(); $iter->valid(); $iter->next()) {
$node = $iter->getRealPath();
if (!is_readable($node)) {
continue;
}
// Check if file or directory is older than the given time.
if ($modifieddateobject[$node] < $time) {
if ($iter->isDir() && !$iter->isDot()) {
// Don't attempt to delete the directory if it isn't empty.
if (!glob($node . DIRECTORY_SEPARATOR . '*')) {
if (@rmdir($node) === false) {
mtrace("Failed removing directory '{$node}'.");
}
}
}
if ($iter->isFile()) {
if (@unlink($node) === false) {
mtrace("Failed removing file '{$node}'.");
}
}
} else {
// Return the time modified to the original date only for real files.
if ($iter->isDir() && !$iter->isDot()) {
touch($node, $modifieddateobject[$node]);
}
}
}
}
示例8: delete
public function delete()
{
if (!$this->loadData()) {
$this->dataError();
sendBack();
}
$moduleobject = $this->_uses[$this->modeltype];
$db = DB::Instance();
$db->StartTrans();
if ($moduleobject->isLoaded()) {
$modulename = $moduleobject->name;
$modulelocation = FILE_ROOT . $moduleobject->location;
if ($moduleobject->enabled && !$moduleobject->disable()) {
$errors[] = 'Failed to disable module';
}
if ($moduleobject->registered && !$moduleobject->unregister()) {
$errors[] = 'Failed to unregister module';
}
if (!$moduleobject->delete()) {
$errors[] = 'Failed to delete module';
} else {
$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($modulelocation), RecursiveIteratorIterator::CHILD_FIRST);
for ($dir->rewind(); $dir->valid(); $dir->next()) {
if ($dir->isDir()) {
rmdir($dir->getPathname());
} else {
unlink($dir->getPathname());
}
}
rmdir($modulelocation);
}
} else {
$errors[] = 'Cannot find module';
}
$flash = Flash::Instance();
if (count($errors) > 0) {
$db->FailTrans();
$flash->addErrors($errors);
if (isset($this->_data['id'])) {
$db->CompleteTrans();
sendTo($this->name, 'view', $this->_modules, array('id' => $this->_data['id']));
}
} else {
$flash->addMessage('Module ' . $modulename . ' deleted OK');
}
$db->CompleteTrans();
sendTo($this->name, 'index', $this->_modules);
}
示例9: addDirectory
public function addDirectory($path, $localpath = null, $exclude_hidden = true)
{
if ($localpath === null) {
$localpath = $path;
}
$localpath = rtrim($localpath, '/\\');
$path = rtrim($path, '/\\');
$iter = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
while ($iter->valid()) {
if (!$iter->isDot() && !$iter->isDir()) {
if (!$exclude_hidden || !$this->is_path_hidden($iter->key())) {
$this->addFile($iter->key(), $localpath . DIRECTORY_SEPARATOR . $iter->getSubPathName());
}
}
$iter->next();
}
}
示例10: execute
/**
* Execute the command.
*
* @return void
*
* @since 1.0
*/
public function execute()
{
$this->getApplication()->outputTitle('Make Documentation');
$this->usePBar = $this->getApplication()->get('cli-application.progress-bar');
if ($this->getApplication()->input->get('noprogress')) {
$this->usePBar = false;
}
$this->github = $this->getContainer()->get('gitHub');
$this->getApplication()->displayGitHubRateLimit();
/* @type \Joomla\Database\DatabaseDriver $db */
$db = $this->getContainer()->get('db');
$docuBase = JPATH_ROOT . '/Documentation';
/* @type \RecursiveDirectoryIterator $it */
$it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($docuBase, \FilesystemIterator::SKIP_DOTS));
$this->out('Compiling documentation in: ' . $docuBase)->out();
$table = new ArticlesTable($db);
// @todo compile the md text here.
$table->setGitHub($this->github);
while ($it->valid()) {
if ($it->isDir()) {
$it->next();
continue;
}
$file = new \stdClass();
$file->filename = $it->getFilename();
$path = $it->getSubPath();
$page = substr($it->getFilename(), 0, strrpos($it->getFilename(), '.'));
$this->debugOut('Compiling: ' . $page);
$table->reset();
$table->{$table->getKeyName()} = null;
try {
$table->load(array('alias' => $page, 'path' => $path));
} catch (\RuntimeException $e) {
// New item
}
$table->is_file = '1';
$table->path = $it->getSubPath();
$table->alias = $page;
$table->text_md = file_get_contents($it->key());
$table->store();
$this->out('.', false);
$it->next();
}
$this->out()->out('Finished =;)');
}
示例11: _recursive_rmdir
/**
* Attempts to remove recursively the directory named by dirname.
*
* @author Mehdi Kabab <http://pioupioum.fr>
* @copyright Copyright (C) 2009 Mehdi Kabab
* @license http://www.gnu.org/licenses/gpl.html GNU GPL version 3 or later
*
* @param string $dirname Path to the directory.
* @return null
*/
private function _recursive_rmdir($dirname)
{
if (is_dir($dirname) && !is_link($dirname)) {
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dirname), \RecursiveIteratorIterator::CHILD_FIRST);
while ($iterator->valid()) {
if (!$iterator->isDot()) {
if ($iterator->isFile()) {
unlink($iterator->getPathName());
} else {
if ($iterator->isDir()) {
rmdir($iterator->getPathName());
}
}
}
$iterator->next();
}
unset($iterator);
// Fix for Windows.
rmdir($dirname);
}
}
示例12: doModel
//.........这里部分代码省略.........
@unlink(osc_content_path() . 'downloads/' . $filename);
if ($fail == 0) {
// Everything is OK, continue
/************************
*** UPGRADE DATABASE ***
************************/
$error_queries = array();
if (file_exists(osc_lib_path() . 'osclass/installer/struct.sql')) {
$sql = file_get_contents(osc_lib_path() . 'osclass/installer/struct.sql');
$conn = DBConnectionClass::newInstance();
$c_db = $conn->getOsclassDb();
$comm = new DBCommandClass($c_db);
$error_queries = $comm->updateDB(str_replace('/*TABLE_PREFIX*/', DB_TABLE_PREFIX, $sql));
}
if ($error_queries[0]) {
// Everything is OK, continue
/**********************************
** EXECUTING ADDITIONAL ACTIONS **
**********************************/
if (file_exists(osc_lib_path() . 'osclass/upgrade-funcs.php')) {
// There should be no errors here
define('AUTO_UPGRADE', true);
require_once osc_lib_path() . 'osclass/upgrade-funcs.php';
}
// Additional actions is not important for the rest of the proccess
// We will inform the user of the problems but the upgrade could continue
/****************************
** REMOVE TEMPORARY FILES **
****************************/
$path = ABS_PATH . 'oc-temp';
$rm_errors = 0;
$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST);
for ($dir->rewind(); $dir->valid(); $dir->next()) {
if ($dir->isDir()) {
if ($dir->getFilename() != '.' && $dir->getFilename() != '..') {
if (!rmdir($dir->getPathname())) {
$rm_errors++;
}
}
} else {
if (!unlink($dir->getPathname())) {
$rm_errors++;
}
}
}
if (!rmdir($path)) {
$rm_errors++;
}
$deleted = @unlink(ABS_PATH . '.maintenance');
if ($rm_errors == 0) {
$message = __('Everything looks good! Your Osclass installation is up-to-date');
} else {
$message = __('Nearly everything looks good! Your Osclass installation is up-to-date, but there were some errors removing temporary files. Please manually remove the "oc-temp" folder');
$error = 6;
// Some errors removing files
}
} else {
$sql_error_msg = $error_queries[2];
$message = __('Problems when upgrading the database');
$error = 5;
// Problems upgrading the database
}
} else {
$message = __('Problems when copying files. Please check your permissions. ');
$error = 4;
// Problems copying files. Maybe permissions are not correct
示例13: createExportZip
/**
* @return string Name of the export zip file
* @throws \Cms\Exception
*/
protected function createExportZip()
{
$zipFile = $this->currentExportDirectory . DIRECTORY_SEPARATOR . $this->currentExportName . '.' . self::EXPORT_FILE_EXTENSION;
$zip = new \ZipArchive();
if ($zip->open($zipFile, \ZipArchive::CREATE | \ZipArchive::OVERWRITE) !== true) {
throw new CmsException(36, __METHOD__, __LINE__, array('file' => $zipFile));
}
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->currentExportDirectory), \RecursiveIteratorIterator::SELF_FIRST);
while ($iterator->valid()) {
if (!$iterator->isDot()) {
if ($iterator->isDir()) {
$test = $iterator->getSubPathName();
$zip->addEmptyDir(str_replace('\\', '/', $iterator->getSubPathName()));
} else {
$test = $iterator->getSubPathName();
$zip->addFile($iterator->key(), str_replace('\\', '/', $iterator->getSubPathName()));
}
}
$iterator->next();
}
$zip->close();
return $zipFile;
}
示例14: time
$config->start_time = time();
if (!$config->quiet) {
$output->e('');
$output->e('Scan started on: ' . date("Y-m-d H:i:s", time()), 1, 'white');
$output->e("Files: ", 0, 'white');
// 30 characters of padding at the end
}
/* The main iterator and some runtime variables */
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('./'));
$infected = array();
$scanned = 0;
$hits = 0;
/* And off we go into the loop */
while ($it->valid()) {
try {
if (!$it->isDot() and !$it->isDir()) {
// First check the MD5 sum of the file.
// Matched files will not be opened for reading to save time.
// Only scan files bigger than 0 bytes and less than 2MB
$fmd5 = md5_file($it->key());
// Check if AppFocus has been defined and process the file first.
if ($config->app_focused_run) {
if (!$config->afo->hash_match($it->key(), $fmd5)) {
$hits++;
$infected[$it->getRealPath()] = array('explain' => '[modified_core_file]', 'score' => 100);
$it->next();
continue;
}
}
if ($it->getSize() > 0 and $it->getSize() < 2048576) {
if (in_array($fmd5, $false_positives)) {
示例15: RecursiveDirectoryIterator
/**
* Step 1: Require the Slim Framework
*
* If you are not using Composer, you need to require the
* Slim Framework and register its PSR-0 autoloader.
*
* If you are using Composer, you can skip this step.
*/
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
//load WRR namespace
$dir_iterator = new RecursiveDirectoryIterator('./wrr');
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
$availableCommands = [];
foreach ($iterator as $fileInfo) {
if ($iterator->isDot() || $iterator->isDir()) {
continue;
}
require $fileInfo->getPath() . DIRECTORY_SEPARATOR . $fileInfo->getFilename();
}
/**
* Step 2: Instantiate a Slim application
*
* This example instantiates a Slim application using
* its default settings. However, you will usually configure
* your Slim application now by passing an associative array
* of setting names and values into the application constructor.
*/
$app = new \Slim\Slim();
require '.env';
if (empty($user) || empty($pass) || empty($host) || empty($dbname)) {