/** * 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); }
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)); } }
/** * 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}'."); } } } } }
/** * 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]); } } } }
/** * 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); } }
/** * Executes the transformation process. * * @throws Zend_Console_Getopt_Exception * * @return void */ public function execute() { $results = array(); $longest_name = 0; /** @var RecursiveDirectoryIterator $files */ $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/../')); while ($files->valid()) { // skip abstract files if (!$files->isFile() || $files->getBasename() == 'Abstract.php') { $files->next(); continue; } // convert the filename to a class $class_name = 'DocBlox_Task_' . str_replace(DIRECTORY_SEPARATOR, '_', $files->getSubPath()) . '_' . $files->getBasename('.php'); // check if the class exists, if so: add it to the list if (class_exists($class_name)) { $name = $files->getBasename('.php'); $longest_name = max(strlen($name), $longest_name); $results[strtolower($files->getSubPath())][strtolower($name)] = $files->getRealPath(); } $files->next(); } // echo the list of namespaces with their tasks ksort($results, SORT_STRING); foreach ($results as $namespace => $tasks) { echo $namespace . PHP_EOL; asort($tasks, SORT_STRING); foreach ($tasks as $task => $filename) { // get the short description by reflecting the file. $refl = new DocBlox_Reflection_File($filename, false); $refl->setLogLevel(DocBlox_Core_Log::QUIET); $refl->process(); /** @var DocBlox_Reflection_Class $class */ $class = current($refl->getClasses()); echo ' :' . str_pad($task, $longest_name + 2) . $class->getDocBlock()->getShortDescription() . PHP_EOL; } } echo PHP_EOL; }
function UnlinkDPL() { global $TopDirectory; try { $TopDirectoryCnt = count($TopDirectory); //print "TopDirectoryCnt: " . $TopDirectoryCnt . $NL; foreach ($TopDirectory as $Dir => $RM) { $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($Dir)); while ($it->valid()) { if ($it->isFile()) { $ext = pathinfo($it->current(), PATHINFO_EXTENSION); if ($ext == "dpl") { unlink($it->getPathName()); } } $it->next(); } } } catch (Exception $e) { echo $e->getMessage(); } }
function get_image_file_array($folder) { $count = 0; $images = array(); $image_data = array(); $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folder)); $ext = array('.png', '.jpeg', '.jpg', '.jpe', '.gif', '.png', '.bmp', 'tif', 'tiff', '.ico'); $skip_paths = explode("\r\n", get_option('image_cleanup_skip_paths', null)); $skip_paths[] = 'imagecleanup'; $start = microtime(true); $debuglog = self::$UPLOAD_DIR . '/imagecleanup/debug.json'; while ($it->valid()) { if (!$it->isDot()) { if ($it->isFile()) { if ($this->strposa($it->getFilename(), $ext) !== false) { //$image_data['att_id'] = 'uknown'; $image_data['bd'] = dirname($it->key()); $image_data['fn'] = $it->getFilename(); $image_data['xist'] = true; //stupid, yes-- but it saves a file_exist later on? $skip = false; $file = $image_data['bd'] . '/' . $image_data['fn']; // check if path in skip array foreach ($skip_paths as $key) { // check if str in complete path and filename if (stripos($file, $key) !== false) { $skip = true; } } if (!$skip) { $images[] = $image_data; } $count++; } } } $it->next(); } return $images; }
public function removeDirectory($directory, $recursive = false) { $directory = $this->path($directory); // Recursive if ($recursive) { $return = true; // Iterate over contents $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::KEY_AS_PATHNAME), RecursiveIteratorIterator::CHILD_FIRST); foreach ($it as $key => $child) { if ($child->getFilename() == '..' || $child->getFilename() == '.') { continue; } if ($child->isDir()) { $return &= $this->removeDirectory($child->getPathname(), false); } else { if ($it->isFile()) { $return &= $this->unlink($child->getPathname(), false); } } } $return &= $this->removeDirectory($directory, false); } else { $return = @rmdir($directory); } if (false === $return) { throw new Engine_Vfs_Adapter_Exception(sprintf('Unable to remove directory "%s"', $directory)); } return $return; }
* @copyright Copyright (c) 2010-2011 lab2023 - * internet technologies TURKEY Inc. (http://www.lab2023.com) * @license http://www.kebab-project.com/cms/licensing * @version 1.5.0 */ /** * Kebab Project Asset Loader * * On-Demad load and return all js files * @uses SPL - Standard PHP Library :: RecursiveIteratorIterator, RecursiveDirectoryIterator */ if (phpversion() < 5) { exit('/* Kebab Project Asset Loader requires PHP5 or greater. */'); } ob_start("ob_gzhandler"); header("Content-type: text/javascript; charset: UTF-8"); // Define root path defined('BASE_PATH') || define('BASE_PATH', realpath(dirname(__FILE__)) . '/'); // Recursive scan directory and files $scanner = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(BASE_PATH)); while ($scanner->valid()) { if (!$scanner->isDot() && $scanner->isFile()) { $pathInfo = pathinfo($scanner->key()); if (@$pathInfo['extension'] == 'js') { @readfile($scanner->key()); print PHP_EOL; } } $scanner->next(); } ob_end_flush();
public static function fsRmdirRecursive($path, $includeSelf = false) { $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::KEY_AS_PATHNAME), RecursiveIteratorIterator::CHILD_FIRST); foreach ($it as $key => $child) { if ($child->getFilename() == '.' || $child->getFilename() == '..') { continue; } if ($it->isDir()) { if (!rmdir($key)) { throw new Engine_Package_Exception(sprintf('Unable to remove directory: %s', $key)); } } else { if ($it->isFile()) { if (!unlink($key)) { throw new Engine_Package_Exception(sprintf('Unable to remove file: %s', $key)); } } } } if (is_dir($path) && $includeSelf) { if (!rmdir($path)) { throw new Engine_Package_Exception(sprintf('Unable to remove directory: %s', $path)); } } }
/** * Recursively remove a directory * * @param string $dirname * @param boolean $followSymlinks * @return boolean */ function RecursiveRmdir($dirname, $followSymlinks = false) { if (is_dir($dirname) && !is_link($dirname)) { if (!is_writable($dirname)) { throw new \Exception(sprintf('%s is not writable!', $dirname)); } $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dirname), \RecursiveIteratorIterator::CHILD_FIRST); while ($iterator->valid()) { if (!$iterator->isDot()) { if (!$iterator->isWritable()) { throw new \Exception(sprintf('%s is not writable!', $iterator->getPathName())); } if ($iterator->isLink() && $followLinks === false) { $iterator->next(); } if ($iterator->isFile()) { @unlink($iterator->getPathName()); } elseif ($iterator->isDir()) { @rmdir($iterator->getPathName()); } } $iterator->next(); } unset($iterator); return @rmdir($dirname); } else { throw new \Exception(sprintf('%s does not exist!', $dirname)); } }
/** * Returns the list of files for Photon. * * This is an array with the key being the path to use in the phar * and the value the path on disk. photon.php and * photon/autoload.php are not included. * * @return array files */ public function getPhotonFiles() { $out = array(); $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->photon_path), \RecursiveIteratorIterator::SELF_FIRST); foreach ($files as $disk_path => $file) { if (!$files->isFile()) { continue; } $phar_path = substr($disk_path, strlen($this->photon_path) + 1); if (false !== strpos($phar_path, 'photon/tests/')) { $this->verbose("[PHOTON IGNORE] " . $phar_path); continue; } if (false !== strpos($phar_path, 'photon/data/project_template')) { $this->verbose("[PHOTON IGNORE] " . $phar_path); continue; } if ($phar_path == 'photon/autoload.php') { $this->verbose("[PHOTON IGNORE] " . $phar_path); continue; } if ($phar_path == 'photon.php') { $this->verbose("[PHOTON IGNORE] " . $phar_path); continue; } $out[$phar_path] = $disk_path; $this->verbose("[PHOTON ADD] " . $phar_path); } return $out; }
$scriptFilename = "scripts/{$binary}.php"; $pharFilename = "bin/{$binary}.phar"; $binaryFilename = "bin/{$binary}"; if (file_exists($pharFilename)) { Phar::unlinkArchive($pharFilename); } if (file_exists($binaryFilename)) { Phar::unlinkArchive($binaryFilename); } $phar = new Phar($pharFilename, FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO, $binary); $phar->startBuffering(); $directories = array('src', 'vendor', 'scripts'); foreach ($directories as $dirname) { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirname)); while ($iterator->valid()) { if ($iterator->isFile()) { $path = $iterator->getPathName(); if ('php' == strtolower($iterator->getExtension())) { $contents = php_strip_whitespace($path); $phar->addFromString($path, $contents); } else { $phar->addFile($path); } } $iterator->next(); } } $stub = "#!/usr/bin/env php\n" . $phar->createDefaultStub($scriptFilename); $phar->setStub($stub); $phar->compressFiles(Phar::GZ); $phar->stopBuffering();
function Main($DoLevel) { global $NL; global $RootMenu; global $SubMenuType; global $TopDirectory; global $AppDir; global $DATABASE_FILENAME; $AppDir = "site/"; if (!file_exists($AppDir . "folder")) { mkdir($AppDir . "folder"); } if (!file_exists($AppDir . "sprites")) { mkdir($AppDir . "sprites"); } $NumNewPlaylists = 0; //Create a didl file in each directory containing music if ($DoLevel > 3) { echo "Removing old .dpl files" . $NL; UnlinkDPL(); } echo "Making a didl file in each directory..." . $NL; $NumNewPlaylists = MakePlaylists($TopDirectory); echo " - found {$NumNewPlaylists} new playlists" . $NL; unlink($DATABASE_FILENAME); $musicDB = new MusicDB(); echo "Find all didl files and add to Menu tree..." . $NL; // Find all didl files and add it to the menus try { CreateAllGreyImgs($musicDB->MaxPreset()); foreach ($TopDirectory as $Dir => $RootMenuNo) { $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($Dir)); while ($it->valid()) { if ($it->isFile()) { $ext = pathinfo($it->current(), PATHINFO_EXTENSION); if ($ext == "xml") { $didl = new DIDL_Album($it->getPathName(), $RootMenuNo); $rowid = $musicDB->CheckURLExist($didl->URI()); if ($rowid === false) { $rowid = Make_Album($didl, $musicDB); Make_Tracks($didl, $musicDB); //$didl->dump(); } else { $didl->SetSequenceNo($rowid); } CollectFolderImgs($didl); echo "."; } } $it->next(); } } } catch (Exception $e) { echo $e->getMessage(); } copy("index.php", $AppDir . "index.php"); copy("html_parts.php", $AppDir . "html_parts.php"); copy("actions.js", $AppDir . "actions.js"); copy("musik.css", $AppDir . "musik.css"); copy("LinnDS-jukebox-daemon.php", $AppDir . "LinnDS-jukebox-daemon.php"); copy("ServerState.php", $AppDir . "ServerState.php"); copy("LPECClientSocket.php", $AppDir . "LPECClientSocket.php"); copy("LinnDSClientSocket.php", $AppDir . "LinnDSClientSocket.php"); copy("StringUtils.php", $AppDir . "StringUtils.php"); copy("SocketServer.php", $AppDir . "SocketServer.php"); copy("LinnDS-jukebox-daemon-old.php", $AppDir . "LinnDS-jukebox-daemon-old.php"); copy("S98linn_lpec", $AppDir . "S98linn_lpec"); copy("Transparent.gif", $AppDir . "Transparent.gif"); copy("setup.php", $AppDir . "setup.php"); copy("Send.php", $AppDir . "Send.php"); copy("MusicDB.php", $AppDir . "MusicDB.php"); copy("QueryAlbum.php", $AppDir . "QueryAlbum.php"); copy("QueryAlbumList.php", $AppDir . "QueryAlbumList.php"); copy("QueryAlphabetPresent.php", $AppDir . "QueryAlphabetPresent.php"); copy("QueryDB.php", $AppDir . "QueryDB.php"); copy("QueryPlayingNowDB.php", $AppDir . "QueryPlayingNowDB.php"); echo "Making sprites and css file in " . $AppDir . $NL; Make_CSS($musicDB->MaxPreset(), $AppDir . "sprites/sprites.css", $AppDir . "sprites/sprites@2x.css"); $musicDB->close(); copy($DATABASE_FILENAME, $AppDir . $DATABASE_FILENAME); echo "Finished..." . $NL; }
/** * Return the MD5 hash of the folder * * @return string The MD5 has */ protected function getHash() { $arrFiles = array(); $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(TL_ROOT . '/' . $this->strFolder, \FilesystemIterator::UNIX_PATHS)); while ($it->valid()) { if ($it->isFile() && $it->getFilename() != '.DS_Store') { $arrFiles[] = $it->getSubPathname(); $arrFiles[] = md5_file($it->getPathname()); } $it->next(); } return md5(implode('-', $arrFiles)); }
public static function build($directory) { $list = array(); $unique = array(); // Build $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::KEY_AS_PATHNAME), RecursiveIteratorIterator::SELF_FIRST); while ($it->valid()) { $key = $it->key(); // Make sure it's unique, Skip .svn files if (isset($unique[$key]) || stripos($key, '.svn') !== false) { $it->next(); continue; } $unique[$key] = true; // Add $subpath = $it->getSubPathName(); // Skip dot files, package files and .svn or CVS folders if (!$it->isDot() && substr(basename($subpath), 0, strrpos(basename($subpath), '.')) != 'package' && basename($subpath) != '.svn' && basename($subpath) != 'CVS') { $key = $it->key(); //$list[$it->getSubPathName()] = array( $list[] = array('path' => self::fix_path($it->getSubPathName()), 'dir' => $it->isDir(), 'file' => $it->isFile(), 'perms' => substr(sprintf('%o', $it->getPerms()), -4), 'size' => $it->getSize(), 'sha1' => $it->isFile() ? sha1_file($key) : null); } $it->next(); } ksort($list); return $list; }
private function copy_them() { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->current_dir, FilesystemIterator::SKIP_DOTS)); while ($iterator->valid()) { if ($iterator->isFile()) { copy($iterator->getPathname(), $this->moved_dir . '/' . $iterator->getFilename()); } $iterator->next(); } }
/** * Delete files and directories older than one week from directory provided by $CFG->tempdir. * * @exception Exception Failed reading/accessing file or directory * @return bool True on successful file and directory deletion; otherwise, false on failure */ function cron_delete_from_temp() { global $CFG; $tmpdir = $CFG->tempdir; // Default to last weeks time. $time = strtotime('-1 week'); try { $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()) { if (@rmdir($node) === false) { mtrace("Failed removing directory '{$node}'."); } } if ($iter->isFile()) { if (@unlink($node) === false) { mtrace("Failed removing file '{$node}'."); } } } } } catch (Exception $e) { mtrace('Failed reading/accessing file or directory.'); return false; } return true; }
/** * Deletes registered files at request shutdown. * * This function should never be called manually; it is registered as a * shutdown function by Horde_Util::deleteAtShutdown() and called * automatically at the end of the request. * * Contains code from gpg_functions.php. * Copyright 2002-2003 Braverock Ventures */ public static function shutdown() { $ptr =& self::$_shutdowndata; foreach (array_keys($ptr['paths']) as $val) { if (@is_file($val)) { self::_secureDelete($val); continue; } try { $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($val), RecursiveIteratorIterator::CHILD_FIRST); } catch (UnexpectedValueException $e) { continue; } while ($it->valid()) { if (!$it->isDot()) { if ($it->isDir()) { @rmdir($it->key()); } elseif ($it->isFile()) { self::_secureDelete($it->key()); } else { @unlink($it->key()); } } $it->next(); } @rmdir($val); } }
protected function getFilesFromDirectory($dir, $ext = null) { $files = array(); $it = new RecursiveDirectoryIterator($dir ? $dir : '.'); $it = new RecursiveIteratorIterator($it); while ($it->valid()) { if (!$it->isDot() && $it->isFile() && (!$ext || pathinfo($it->key(), PATHINFO_EXTENSION) == $ext)) { $files[$it->key()] = true; } $it->next(); } return array_keys($files); }