Esempio n. 1
0
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);
}
 /**
  * Returns true if file is valid.
  * Valid Files: Directories and Files not beginning with a "." (dot).
  *
  * @todo make it more flexible to handle hidden dirs on demand etc,
  * win/*nix compat
  * 
  * @return boolean if current file entry is vali
  */
 public function valid()
 {
     if (parent::valid()) {
         if (parent::isDot() || parent::isDir() && strpos(parent::getFilename(), '.') === 0) {
             parent::next();
             // zum nächsten eintrag hüpfen
             return $this->valid();
             // nochmal prüfen
         }
         return true;
     }
     return false;
 }
Esempio n. 3
0
 /**
  * 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;
 }
 /**
  * fills the list of availible files, with DirectoryIterator object as value
  *
  * @return void
  */
 protected function scanFilesObj()
 {
     if (!empty($this->filesObj)) {
         return;
     }
     if ($this->recursive) {
         $it = new RecursiveIteratorIterator($this->obj, RecursiveIteratorIterator::CHILD_FIRST);
         foreach ($it as $filename => $obj) {
             if ($it->isDot()) {
                 continue;
             }
             $this->filesObj[$filename] = $obj;
         }
     } else {
         foreach ($this->obj as $filename => $obj) {
             if ($this->obj->isDot()) {
                 continue;
             }
             $this->filesObj[$obj->getFilename()] = $obj;
         }
     }
 }
Esempio n. 5
0
 /**
  * parse this directory
  *
  * @return  none
  */
 protected function parseDir()
 {
     $this->clear();
     $iter = new RecursiveDirectoryIterator($this->getPath());
     while ($iter->valid()) {
         $curr = (string) $iter->getSubPathname();
         if (!$iter->isDot() && $curr[0] != '.') {
             $this->addItem(Varien_Directory_Factory::getFactory($iter->current(), $this->getRecursion(), $this->getRecursionLevel()));
         }
         $iter->next();
     }
 }
Esempio n. 6
0
 /**
  * Deletes all files, directories and subdirectories from the specified
  * directory. The passed directory itself won't be deleted though.
  *
  * @param string $path Path to the directory which shall be emptied.
  * @return void
  * @throws Exception
  * @see removeDirectoryRecursively()
  */
 public static function emptyDirectoryRecursively($path)
 {
     if (!is_dir($path)) {
         throw new \TYPO3\Flow\Utility\Exception('"' . $path . '" is no directory.', 1169047616);
     }
     if (self::is_link($path)) {
         if (self::unlink($path) !== TRUE) {
             throw new \TYPO3\Flow\Utility\Exception('Could not unlink symbolic link "' . $path . '".', 1323697654);
         }
     } else {
         $directoryIterator = new \RecursiveDirectoryIterator($path);
         foreach ($directoryIterator as $fileInfo) {
             if (!$fileInfo->isDir()) {
                 if (self::unlink($fileInfo->getPathname()) !== TRUE) {
                     throw new \TYPO3\Flow\Utility\Exception('Could not unlink file "' . $fileInfo->getPathname() . '".', 1169047619);
                 }
             } elseif (!$directoryIterator->isDot()) {
                 self::removeDirectoryRecursively($fileInfo->getPathname());
             }
         }
     }
 }
Esempio n. 7
0
 function remove($dirname) {
     if (is_dir($dirname)) {
         $dir=new RecursiveDirectoryIterator($dirname);
         foreach ($dir as $k=>$v) {
             if (!$dir->isDot()) {
                 if ($v->isDir()) {
                     self::remove($v->getPathname());
                 }
                 else {
                     unlink($v->getPathname());
                 }
             }
         }
         unset($dir);
         rmdir($dirname);
         return true;
     }
     return false;
 }
 /**
  * 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));
                     }
                 }
             }
         }
     }
 }
Esempio n. 9
0
 /**
  * Recursively go through each folder and extract the archives
  *
  * @param $start
  */
 public function unzipAll($start)
 {
     $iterator = new RecursiveDirectoryIterator($start);
     foreach ($iterator as $file) {
         if ($file->isFile()) {
             $extension = pathinfo($file->getFilename(), PATHINFO_EXTENSION);
             if ($extension == 'zip') {
                 $unzip = $file->getPath() . '/' . $file->getBasename('.' . $extension);
                 $result = JArchive::extract($file->getPathname(), $unzip);
                 //                     delete the archive once we extract it
                 if ($result) {
                     JFile::delete($file->getPathname());
                     //                      now check the new extracted folder for archive files
                     $this->unzipAll($unzip);
                 }
             }
         } else {
             if (!$iterator->isDot()) {
                 $this->unzipAll($file->getPathname());
             }
         }
     }
 }
Esempio n. 10
0
 /**
  * Recursive directory function.
  *
  * @param RecursiveDirectoryIterator $iterator 
  */
 protected function _recurseDirectory($iterator)
 {
     while ($iterator->valid()) {
         if ($iterator->isDir() && !$iterator->isDot()) {
             if ($iterator->hasChildren()) {
                 $this->_recurseDirectory($iterator->getChildren());
             }
         } elseif ($iterator->isFile()) {
             $path = $iterator->getPath() . '/' . $iterator->getFilename();
             $pathinfo = pathinfo($path);
             if ($this->_isPhpFile($path)) {
                 $this->addFile($path);
             }
         }
         $iterator->next();
     }
 }
Esempio n. 11
0
 /**
  * 
  * Recursively iterates through a directory looking for class files.
  * 
  * Skips CVS directories, and all files and dirs not starting with
  * a capital letter (such as dot-files).
  * 
  * @param RecursiveDirectoryIterator $iter Directory iterator.
  * 
  * @return void
  * 
  */
 protected function _fetch(RecursiveDirectoryIterator $iter)
 {
     for ($iter->rewind(); $iter->valid(); $iter->next()) {
         // preliminaries
         $path = $iter->current()->getPathname();
         $file = basename($path);
         $capital = ctype_alpha($file[0]) && $file == ucfirst($file);
         $phpfile = strripos($file, '.php');
         // check for valid class files
         if ($iter->isDot() || !$capital) {
             // skip dot-files (including dot-file directories), as
             // well as files/dirs not starting with a capital letter
             continue;
         } elseif ($iter->isDir() && $file == 'CVS') {
             // skip CVS directories
             continue;
         } elseif ($iter->isDir() && $iter->hasChildren()) {
             // descend into child directories
             $this->_fetch($iter->getChildren());
         } elseif ($iter->isFile() && $phpfile) {
             // map the .php file to a class name
             $len = strlen($this->_base);
             $class = substr($path, $len, -4);
             // drops .php
             $class = str_replace(DIRECTORY_SEPARATOR, '_', $class);
             $this->_map[$class] = $path;
         }
     }
 }
 function valid()
 {
     if (parent::valid()) {
         if (!parent::isDir() || parent::isDot()) {
             parent::next();
             return $this->valid();
         }
         return TRUE;
     }
     return FALSE;
 }