protected function ProcessFile(DirectoryIterator $pParent, DirectoryIterator $pNode) { $oldname = $pNode->getPathname(); $newname = $pParent->getPath() . '\\' . $this->GetLastFolderName($pParent->getPath()) . '.dds'; rename($oldname, $newname); echo '<p>rename <b>' . $oldname . '</b> to <b>' . $newname . '<br/></p>'; }
/** * Método recursivo que busca o arquivo em todas as pastadas dentro do * diretorio específicado * * @param string $dir * @param string $file * @return boolean */ public static function searchInDir($dir, $file) { if (is_file($dir . "/" . $file)) { require_once $dir . "/" . $file; self::$find = true; if (self::$sugests) { $fileName = $dir . "/" . $file; $fileName = str_replace(self::$currentPath, "", $fileName); echo "require_once '" . $fileName . "';<br>\n"; } return true; } if (is_dir($dir)) { $d = new DirectoryIterator($dir); while (!self::$find && $d->valid()) { if (is_dir($d->getPath() . '/' . $d->getFilename())) { //testa se o arquivo pode ser incluido $inc = true; foreach (self::$blockedDirs as $bDir) { if ($d->getFilename() == $bDir) { $inc = false; break; } } if (!$d->isDot() && $inc) { self::searchInDir($d->getPath() . '/' . $d->getFilename(), $file); } } $d->next(); } } return self::$find; }
public function readDir($dirPath) { $di = new DirectoryIterator($dirPath); $array = array(); while ($di->valid()) { if (!$di->isDot() && $this->validateDir($di->getFilename())) { if ($di->isDir()) { $dir = $di->getPath() . '/' . $di->getFilename(); $array[$di->getFilename()] = $this->readDir($di->getPath() . '/' . $di->getFilename()); } else { $array[$di->getFilename()] = $di->getPath() . "/" . $di->getFilename(); } } $di->next(); } return $array; }
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(); }
private function compileAll(\DirectoryIterator $iterator) { $jsContent = ""; /** @var $info \DirectoryIterator */ foreach ($iterator as $info) { if ($info->isFile()) { $jsContent .= $this->compileFile($info); } elseif (!$info->isDot()) { $jsContent .= $this->compileAll(new \DirectoryIterator($iterator->getPath() . DIRECTORY_SEPARATOR . $info->getBasename())); } } return $jsContent; }
public function getPlugins() { $output = array(); $it = new DirectoryIterator(BASE . 'plugins/'); while ($it->valid()) { $xml_path = $it->getPath() . $it->getFilename() . '/'; $xml_file = $xml_path . "plugin.xml"; if ($it->isReadable() && $it->isDir() && file_exists($xml_file)) { $output[] = new PapyrinePlugin($xml_path); } $it->next(); } return $output; }
/** * Compacta todos os arquivos .php de um diretório removendo comentários, * espaços e quebras de linhas desnecessárias. * motivos de desempenho e segurança esse método so interage em um diretório * de cada vez. * * @param string $directoryPath * @param string $newFilesDirectory * @param string $newFilesPrefix * @param string $newFilesSufix */ public static function cleanDir($directoryPath, $newFilesDirectory = "packed", $newFilesPrefix = "", $newFilesSufix = "") { $dir = new DirectoryIterator($directoryPath); mkdir($directoryPath . "/{$newFilesDirectory}/"); while ($dir->valid()) { if (!$dir->isDir() and !$dir->isDot() and substr($dir->getFilename(), -3, 3) == 'php') { $str = self::cleanFile($dir->getPathname()); $fp = fopen($dir->getPath() . "/packed/" . $newFilesPrefix . $dir->getFilename() . $newFilesSufix, "w"); fwrite($fp, $str); fclose($fp); echo $dir->getPathname() . ' - Renomeado com sucesso <br />'; } $dir->next(); } }
/** * Iteratively remove/delete a directory and its contents * * @param DirectoryIterator $path base directory (inclusive) to recursively delete. */ function recursivelyDeleteDirectory(DirectoryIterator $path) { // echo $path . " being deleted?"; if ($path->isDir()) { $directory = new DirectoryIterator($path->getPath() . DIRECTORY_SEPARATOR . $path->getFilename()); // For each element within this directory, delete it or recurse into next directory foreach ($directory as $object) { if (!$object->isDot()) { if ($object->isDir()) { recursivelyDeleteDirectory($object); } else { unlink($object->getPathname()); } } } rmdir($path->getPathname()); } else { // Not a directory... // Do nothing } }
<?php // no direct access defined('PARENT_FILE') or die('Restricted access'); if ($this->authorize()) { $confirm = file_get_contents(__SITE_PATH . '/templates/' . $this->registry->template . '/html/confirm.html'); $js = new JsLoader($this->registry); $js->source_root = $this->registry->config->get('web_url', 'SERVER') . '/Common/javascript/Source/'; $dirs = array($_SERVER['DOCUMENT_ROOT'] . '/templates/', $_SERVER['DOCUMENT_ROOT'] . '/../templates/'); foreach ($dirs as $dir) { $iterator = new DirectoryIterator($dir); $path = $iterator->getPath(); foreach ($iterator as $fileinfo) { if (!$fileinfo->isDot()) { if ($fileinfo->isDir()) { $templates[$fileinfo->getFilename()] = $path . '/' . $fileinfo->getFilename(); } } } unset($iterator); } ksort($templates); if (isset($_POST['template'])) { $template = $templates[$_POST['template']]; $template_name = $_POST['template']; } else { $template = $templates[$this->registry->admin_config->get('admin_template', 'SERVER')]; $template_name = $this->registry->admin_config->get('admin_template', 'SERVER'); } $template_files = new Admin_Config($this->registry, array('path' => $template . '/ini/template.ini.php')); $template_files->public_html = true;
protected function execute(InputInterface $input, OutputInterface $output) { // Fetch all the aliases $aliases = $this->mimetypeDetector->getAllAliases(); // Remove comments $keys = array_filter(array_keys($aliases), function ($k) { return $k[0] === '_'; }); foreach ($keys as $key) { unset($aliases[$key]); } // Fetch all files $dir = new \DirectoryIterator(\OC::$SERVERROOT . '/core/img/filetypes'); $files = []; foreach ($dir as $fileInfo) { if ($fileInfo->isFile()) { $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename()); $files[] = $file; } } //Remove duplicates $files = array_values(array_unique($files)); // Fetch all themes! $themes = []; $dirs = new \DirectoryIterator(\OC::$SERVERROOT . '/themes/'); foreach ($dirs as $dir) { //Valid theme dir if ($dir->isFile() || $dir->isDot()) { continue; } $theme = $dir->getFilename(); $themeDir = $dir->getPath() . '/' . $theme . '/core/img/filetypes/'; // Check if this theme has its own filetype icons if (!file_exists($themeDir)) { continue; } $themes[$theme] = []; // Fetch all the theme icons! $themeIt = new \DirectoryIterator($themeDir); foreach ($themeIt as $fileInfo) { if ($fileInfo->isFile()) { $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename()); $themes[$theme][] = $file; } } //Remove Duplicates $themes[$theme] = array_values(array_unique($themes[$theme])); } //Generate the JS $js = '/** * This file is automatically generated * DO NOT EDIT MANUALLY! * * You can update the list of MimeType Aliases in config/mimetypealiases.json * The list of files is fetched from core/img/filetypes * To regenerate this file run ./occ maintenance:mimetypesjs */ OC.MimeTypeList={ aliases: ' . json_encode($aliases, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . ', files: ' . json_encode($files, JSON_PRETTY_PRINT) . ', themes: ' . json_encode($themes, JSON_PRETTY_PRINT) . ' }; '; //Output the JS file_put_contents(\OC::$SERVERROOT . '/core/js/mimetypelist.js', $js); $output->writeln('<info>mimetypelist.js is updated'); }
protected static function _deleteDir($dirPath) { $iterator = new DirectoryIterator($dirPath); foreach ($iterator as $fileInfo) { if ($fileInfo->isDot()) { continue; } if ($fileInfo->isDir()) { self::_deleteDir($fileInfo->getPathname()); } else { unlink($fileInfo->getPathname()); } } rmdir($iterator->getPath()); }
/** * Generate app skeleton on current directory * * @param string Namespace * @return stream */ public static function generate($namespace = 'App') { $namespace = ucfirst(strtolower($namespace)); $isApp = (bool) ($namespace === 'App'); $currentDirectory = new \DirectoryIterator($_SERVER['PWD']); // Initialize by validate current directory if ($currentDirectory->isDir() && $currentDirectory->isWritable()) { // Create directory structure self::out(I18n::translate('command_generate_folders')); $appFolder = $currentDirectory->getPath() . DIRECTORY_SEPARATOR . $namespace; $controllerFolder = $currentDirectory->getPath() . DIRECTORY_SEPARATOR . $namespace . DIRECTORY_SEPARATOR . 'Controller'; $testsFolder = $currentDirectory->getPath() . DIRECTORY_SEPARATOR . $namespace . DIRECTORY_SEPARATOR . 'Tests'; $directories = compact('appFolder', 'controllerFolder', 'testsFolder'); foreach ($directories as $name => $directory) { $directory = $isApp ? str_replace($namespace, strtolower($namespace), $directory) : $directory; is_dir($directory) or mkdir($directory, 0755, TRUE); // Reset paths ${$name} = $directory; } // Create controller and model self::out(I18n::translate('command_generate_files')); $controllerTemplate = File::read(PATH_SYS . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'Controller.php.tpl'); $phpunitTemplate = File::read(PATH_SYS . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'phpunit.xml.tpl'); $bootstrapTemplate = File::read(PATH_SYS . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'bootstrap.php.tpl'); $testTemplate = File::read(PATH_SYS . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'ControllerTest.php.tpl'); $routePath = $isApp ? '' : strtolower($namespace) . '.'; File::write($controllerFolder . DIRECTORY_SEPARATOR . 'HelloController.php', sprintf($controllerTemplate, $namespace, $namespace, $namespace)); File::write($testsFolder . DIRECTORY_SEPARATOR . 'phpunit.xml', sprintf($phpunitTemplate, $namespace)); File::write($testsFolder . DIRECTORY_SEPARATOR . 'bootstrap.php', sprintf($bootstrapTemplate, PATH_SYS . DIRECTORY_SEPARATOR . 'Juriya.php')); File::write($testsFolder . DIRECTORY_SEPARATOR . 'HelloControllerTest.php', sprintf($testTemplate, $namespace, $namespace, $routePath, $routePath, $routePath)); // Generate basic YAML configuration files self::out(I18n::translate('command_generate_configuration')); $routesTemplate = File::read(PATH_SYS . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'routes.yml.tpl'); $packagesTemplate = File::read(PATH_SYS . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'packages.yml.tpl'); $modulesTemplate = File::read(PATH_SYS . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'modules.yml.tpl'); File::write($appFolder . DIRECTORY_SEPARATOR . 'routes.yml', sprintf($routesTemplate, $namespace)); File::write($appFolder . DIRECTORY_SEPARATOR . 'packages.yml', $packagesTemplate); File::write($appFolder . DIRECTORY_SEPARATOR . 'modules.yml', $modulesTemplate); if ($isApp) { // Generate front socket if the requsted app is Application self::out(I18n::translate('command_generate_front_socket')); $publicDirectory = $currentDirectory->getPath() . DIRECTORY_SEPARATOR . 'public'; is_dir($publicDirectory) or mkdir($publicDirectory, 0755, TRUE); $indexTemplate = File::read(PATH_SYS . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'index.php.tpl'); File::write($publicDirectory . DIRECTORY_SEPARATOR . 'index.php', sprintf($indexTemplate, PATH_SYS . DIRECTORY_SEPARATOR . 'Juriya.php')); } self::out(Utility::getColoredString(I18n::translate('command_generate_done'), 'black', 'green')); } else { self::out(I18n::translate('file_not_writable', $currentDirectory->getPath())); self::out(Utility::getColoredString(I18n::translate('command_generate_fail'), 'black', 'red')); } }
public static function deleteDir($dirPath) { $iterator = new DirectoryIterator($dirPath); foreach ($iterator as $fileInfo) { if ($fileInfo->isDot()) { continue; } if ($fileInfo->isDir()) { self::deleteDir($fileInfo->getPathname()); } else { $fileName = $fileInfo->getFilename(); if ($fileName[0] == '.') { continue; } unlink($fileInfo->getPathname()); } } rmdir($iterator->getPath()); }
/** * @param DirectoryIterator $fileInfo */ private function patchXml(\DirectoryIterator $fileInfo) { if ($fileInfo->isFile()) { $filePath = $fileInfo->getPathname(); if (!preg_match('/\\.orm\\.xml$/', $fileInfo->getFilename())) { return; } else { preg_match('/(.*)\\.orm\\.xml/', $fileInfo->getFilename(), $m); $className = $m[1]; } //replase $contentMap = ['column="order"' => 'column="`order`"', 'column="from"' => 'column="`from`"', 'column="to"' => 'column="`to`"', 'column="user"' => 'column="`user`"']; $content = file_get_contents($filePath); $content = str_replace(array_keys($contentMap), array_values($contentMap), $content); //rename $filenameMap = []; if (isset($filenameMap[$fileInfo->getFilename()])) { unlink($filePath); $filePath = $fileInfo->getPath() . '/' . $filenameMap[$fileInfo->getFilename()]; } $content = $this->addGedmoLoggable($content, $className); file_put_contents($filePath, $content); } }
/** * Copy file * * @param int $fileID * @param DirectoryIterator $entries * @return void|string */ protected final function _copyFile($fileID, DirectoryIterator $entries) { // Generate storage filename $storeAs = str_replace(array('%scanID%', '%fileID%', '%fullPath%', '%relativePath%', '%filename%', '%to%'), array($this->_scanRow->scanID, $fileID, $entries->getPath() . '/', ltrim(mb_substr($entries->getPath() . '/', mb_strlen($this->_currentRoot)), '/'), $entries->getFilename(), $this->_currentTo), $this->_naming); // Destination $destination = $this->_storagePath . $storeAs; // Check destination directory $path = dirname($destination); if (!realpath($path)) { // Create if (!mkdir($path, $this->_storageDirectoryMode, true)) { $this->_log(self::LOG_ERROR, "\tCan't create {$path}"); return; } } // Copy copy($entries->getPathname(), $destination); // Date if ($this->_copyWithDate) { touch($destination, $entries->getMTime()); } return '/' . $storeAs; }
/** * Set the themeFolders * @param type $themeFolder * @return \Dxapp\Options\ModuleOptions */ public function setThemeFolders($themeFolder) { if (file_exists($themeFolder)) { $folder = new \DirectoryIterator($themeFolder); while ($folder->valid()) { $in = $folder->getFilename(); if ($in != '.' && $in != '..') { $path = $folder->getPath(); $configFile = $path . '/' . $in . '/theme.config.php'; if (file_exists($configFile)) { $themeConfig = (include_once $configFile); $this->addTemplateMap($in, $themeConfig); } } $folder->next(); } } return $this; }
public function loadValidatorsByDir($dir) { $dir = new DirectoryIterator($dir); while ($dir->valid()) { if (!$dir->isDot() && $dir->isDir()) { $validatorfile = $dir->getPath() . '/' . $dir->current() . '/Validator.php'; $validatorclass = 'Config_Validator_' . $dir->current() . 'Node_PartyCal'; $this->loadValidator($validatorclass, $validatorfile); } $dir->next(); } }
/** * Initialise the menu structure from the views found inside the directory * $path. The view.json files are read to produce these menu items. * * @param string $path The path to scan * @param boolean $reset Should I reset the existing items? Default = true */ public function initialiseFromDirectory($path, $reset = true) { $appName = $this->container->application->getName(); if ($reset) { $this->items = array(); } if (!is_dir($path)) { return; } $di = new \DirectoryIterator($path); /** @var \DirectoryIterator $entry */ foreach ($di as $entry) { // Ignore dot files if ($entry->isDot()) { continue; } // Ignore non-directory entities if (!$entry->isDir()) { continue; } // Look for a view.json file and try to load it $sourceFile = $di->getPath() . '/' . $di->getFilename() . '/view.json'; $options = array('show' => array('main')); if (file_exists($sourceFile)) { // Load the view.json file $jsonData = @file_get_contents($sourceFile); $options = json_decode($jsonData, true); if (!is_array($options) || empty($options)) { $options = array('show' => array('main')); } } // If show is empty or doesn't exist, ignore this view if (!array_key_exists('show', $options)) { continue; } elseif (empty($options['show'])) { continue; } $viewName = strtolower($di->getFilename()); // If there are no params set, try to guess! if (!array_key_exists('params', $options)) { $options['params'] = array('view' => $viewName); } // If there is no name set, try to guess! if (!array_key_exists('name', $options)) { $options['name'] = $viewName; } // If there is no title set, try to guess! if (!array_key_exists('title', $options)) { $options['title'] = strtoupper($appName . '_' . $viewName . '_TITLE'); } // If there is no order set, use 0 if (!array_key_exists('order', $options)) { $options['order'] = 0; } // Create a menu item $item = new Item($options, $this->container); // Add the menu item $this->addItem($item); } }
/** * @param string $realpath * @param bool $recursive * @return bool */ public function deleteSubfolder($realpath, $recursive = true) { if (!$this->isCdnPath($realpath)) { return false; } try { $it = new \DirectoryIterator($realpath); } catch (\UnexpectedValueException $e) { return false; } foreach ($it as $file) { if ($file->isDot()) { continue; } if ($file->isFile() && $recursive) { $this->deleteFile($file->getRealPath()); } else { if ($file->isDir() && $realpath !== $file->getRealPath() && $recursive) { $this->deleteSubfolder($file->getRealPath(), $recursive); } } } return rmdir($it->getPath()); }