本文整理汇总了PHP中DirectoryIterator::current方法的典型用法代码示例。如果您正苦于以下问题:PHP DirectoryIterator::current方法的具体用法?PHP DirectoryIterator::current怎么用?PHP DirectoryIterator::current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DirectoryIterator
的用法示例。
在下文中一共展示了DirectoryIterator::current方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cleanDir
protected function cleanDir($dir)
{
$files = new \DirectoryIterator($dir);
while ($files->valid()) {
if (in_array(substr($files->current(), -2), ['.0', '.1'])) {
unlink($dir . '/' . $files->current());
}
$files->next();
}
}
示例2: fromFileScan
/**
* @ignore
*/
public static function fromFileScan($uPattern)
{
$tSep = quotemeta(DIRECTORY_SEPARATOR);
$tPos = strrpos($uPattern, $tSep);
if ($tSep !== '/' && $tPos === false) {
$tSep = '/';
$tPos = strrpos($uPattern, $tSep);
}
if ($tPos !== false) {
$tPattern = substr($uPattern, $tPos + strlen($tSep));
$tPath = substr($uPattern, 0, $tPos + strlen($tSep));
} else {
$tPath = $uPattern;
$tPattern = "";
}
$tTemp = new static();
$tHandle = new \DirectoryIterator($tPath);
$tPatExists = strlen($uPattern) > 0;
for (; $tHandle->valid(); $tHandle->next()) {
if (!$tHandle->isFile()) {
continue;
}
$tFile = $tHandle->current();
if ($tPatExists && !fnmatch($tPattern, $tFile)) {
continue;
}
$tTemp->add(simplexml_load_file($tPath . $tFile));
}
return $tTemp;
}
示例3: current
/**
* Return the current resource.
*
* @return \com\mohiva\common\io\Resource The current `Resource` object or null if no resource
* exists.
*/
public function current()
{
if (!$this->valid()) {
return null;
}
$resource = $this->getResourceLoader()->getResourceByType($this->iterator->current(), $this->resourceType);
return $resource;
}
示例4: rm_recursive
function rm_recursive($path)
{
if (!is_dir($path)) {
return;
}
$dir = new DirectoryIterator($path);
while ($dir->valid()) {
if (!$dir->isDot()) {
if ($dir->isDir()) {
rm_recursive($path . DIRECTORY_SEPARATOR . $dir->current());
} else {
unlink($path . DIRECTORY_SEPARATOR . $dir->current());
}
}
$dir->next();
}
rmdir($path);
}
示例5: current
/**
* Current.
* Please, see \DirectoryIterator::current() method.
*
* @return mixed
*/
public function current()
{
$out = parent::current();
if (null !== $this->_splFileInfoClass && $out instanceof \SplFileInfo) {
$out->setInfoClass($this->_splFileInfoClass);
$out = $out->getFileInfo();
if ($out instanceof \Hoa\Iterator\SplFileInfo) {
$out->setRelativePath($this->getRelativePath());
}
}
return $out;
}
示例6: DirectoryIterator
function __construct($link)
{
$d = new DirectoryIterator($link);
while ($d->valid()) {
$file = $d->current();
if (!$file->isDot()) {
$this->files[] = $file->getFilename();
}
$d->next();
}
$this->path = $d->getPath();
}
示例7: indexAction
function indexAction()
{
setcookie("previewTemplateName", false, 0, "/");
$templates = array();
$dir = new DirectoryIterator(Config::get('TEMPLATES_PATH'));
while ($dir->valid()) {
if (!$dir->isDot()) {
$templates[] = (string) $dir->current();
}
$dir->next();
}
$this->set("alltemplates", $templates);
}
示例8: getImages
function getImages()
{
$filesInFolder = new DirectoryIterator($this->imagePath);
$imageList = array();
$i = 0;
while ($filesInFolder->valid()) {
$file = $filesInFolder->current();
$filename = $file->getFilename();
$src = "{$this->imagePath}/{$filename}";
$fileInfo = new finfo(FILEINFO_MIME_TYPE);
$mimeType = $fileInfo->file($src);
if ($mimeType === "image/jpeg") {
$imageList[$i++] = $src;
}
$filesInFolder->next();
}
return $imageList;
}
示例9: showImages
function showImages()
{
$out = "<h1>Image Gallery</h1>";
$out .= "<ul id='images'>";
$folder = "img";
$filesInFolder = new DirectoryIterator($folder);
while ($filesInFolder->valid()) {
$file = $filesInFolder->current();
$fileName = $file->getFileName();
$src = "{$folder}/{$fileName}";
$fileInfo = new Finfo(FILEINFO_MIME_TYPE);
$mimeType = $fileInfo->file($src);
if ($mimeType === 'image/jpeg') {
$out .= "<li><img src='{$src}' /></li>";
}
$filesInFolder->next();
}
$out .= "</ul>";
return $out;
}
示例10: WalkDirectory
/**
* the recursive function that walks through a directory of given path
*/
protected function WalkDirectory(DirectoryIterator $Directory, $pRecursiveWalk, $depth = 0)
{
$this->mStringFolderTree = str_repeat(' ', $depth * 5) . $Directory->getPathName() . '<br />';
while ($Directory->valid()) {
$node = $Directory->current();
if ($node->isDir() && $node->isReadable() && !$node->isDot()) {
if ($this->FolderFilter($Directory, $node)) {
$this->ProcessFolder($Directory, $node);
}
if ($pRecursiveWalk) {
$this->mStringFolderTree .= $this->WalkDirectory(new DirectoryIterator($node->getPathname()), $pRecursiveWalk, $depth + 1);
}
} elseif ($node->isFile()) {
if ($this->FileFilter($Directory, $node)) {
$this->ProcessFile($Directory, $node);
}
$this->mStringFolderTree .= str_repeat(' ', (1 + $depth) * 5) . $node->getFilename();
}
$Directory->next();
}
return $this->mStringFolderTree;
}
示例11: showImages
function showImages()
{
$out = "<h1>Image Gallery</h1>";
$out .= "<ul id='images'";
$folder = "img";
$filesInFolder = new DirectoryIterator($folder);
//Iterate through the directory for images
//with different file types
while ($filesInFolder->valid()) {
$file = $filesInFolder->current();
$filename = $file->getFilename();
$src = "{$folder}/{$filename}";
$fileInfo = new Finfo(FILEINFO_MIME_TYPE);
$mimeType = $fileInfo->file($src);
if ($mimeType === 'image/jpeg' || $mimeType === 'image/pjpeg' || $mimeType === 'image/png' || $mimeType === 'image/gif') {
$out .= "<li><img src='{$src}' /></li>";
}
$filesInFolder->next();
}
$out .= "</ul>";
return $out;
}
示例12: WalkDirectory
function WalkDirectory(DirectoryIterator $iter, $depth = 0)
{
$return = str_repeat(' ', $depth * 5) . $iter->getPathName() . "\n";
while ($iter->valid()) {
$node = $iter->current();
if ($node->isDir() && $node->isReadable() && !$node->isDot()) {
$return .= WalkDirectory(new DirectoryIterator($node->getPathname()), $depth + 1);
} elseif ($node->isFile()) {
$return .= str_repeat(' ', (1 + $depth) * 5) . $node->getFilename() . "\n";
}
// Rename wf_ to admin_
$oldName = $node->getFilename();
if (strpos($oldName, 'wf_') === 0) {
$newFileName = str_replace('wf_', 'admin_', $node->getFilename());
$path = str_replace('/www/wildflower/', '', $node->getPathname());
$cmd = 'git mv ' . $path . ' ' . str_replace($oldName, $newFileName, $path) . "\n";
$return .= $cmd;
exec($cmd);
}
$iter->next();
}
return $return;
}
示例13: copyDirectory
/**
* Copy a directory within all its items.
*
* @param string $source The source directory
* @param string $target The target to create
* @param array $exclude List of files / folders that should not be copyed
*
* @return void
*/
public function copyDirectory($source, $target, $exclude = array())
{
// first check for target itself
self::createDirectory($target);
$iterator = new DirectoryIterator($source);
while ($iterator->valid()) {
$item = $iterator->current();
// create new file
if ($iterator->isFile()) {
self::copyFile($source . '/' . $item, $target);
}
// create folder recursive
if (!$iterator->isDot() && $iterator->isDir() && !in_array($item, $exclude)) {
self::copyDirectory($source . '/' . $item, $target . '/' . $item);
}
$iterator->next();
}
}
示例14: DirectoryIterator
<?php
$dir = new DirectoryIterator(__DIR__ . '/../../sample_dir');
$files = array();
// order changes per machine
while ($dir->valid()) {
if (!$dir->isDot()) {
$files[] = $dir->current() . "\n";
}
$dir->next();
}
asort($files);
var_dump(array_values($files));
示例15: _cleanUp
/**
* Cleanup the test directory output folder
*
* @param string $dir The directory to clean up
*
* @return void
*/
protected function _cleanUp($dir)
{
$iterator = new DirectoryIterator($dir);
while ($iterator->valid()) {
// delete file
if ($iterator->isFile()) {
unlink($dir . '/' . $iterator->current());
}
// delete folder recursive
if (!$iterator->isDot() && $iterator->isDir()) {
$this->_cleanUp($dir . '/' . $iterator->current());
rmdir($dir . '/' . $iterator->current());
}
$iterator->next();
}
unset($iterator);
}