Get file list from directories: files, beforeUpgradeFiles, afterUpgradeFiles

@param  string $dirPath

@return array
350833
protected function getFileList($dirPath)
    {
        $fileList = array();

        $paths = $this->getFileDirs($dirPath);
        foreach ($paths as $filesPath) {
            if (file_exists($filesPath)) {
                $files = $this->getFileManager()->getFileList($filesPath, true, '', true, true);
                $fileList = array_merge($fileList, $files);
            }
        }

        //vendor file list
        $vendorFileList = $this->getVendorFileList('copy');
        if (!empty($vendorFileList)) {
            $fileList = array_merge($fileList, $vendorFileList);
        }

        return $fileList;
    }
795829
protected function removeRecursiveDirectory(string $dirPath): bool
    {
        $itemList = array_diff(scandir($dirPath), ['.', '..']);
        
        foreach ($itemList as $itemName) {
            $itemPath = $dirPath.'/'.$itemName;
            
            if (is_dir($itemPath)) {
                $this->removeRecursiveDirectory($itemPath);
            } else {
                unlink($itemPath);
            }
        }
        
        return rmdir($dirPath);
    }
445601
public static function listDir($dir = '.')
    {
        $list = [];
        foreach (scandir($dir) as $file) {
            if ($file == '.' || $file == '..') {
                continue;
            } else {
                $list[] = self::fileInfo($dir . DS . $file);
            }
        }
        return $list;
    }
665452
private function deleteFiles($dirPath)
    {
        foreach (glob($dirPath.DIRECTORY_SEPARATOR.'{*,.[!.]*,..?*}', GLOB_BRACE) as $content) {
            if (is_dir($content)) {
                $this->deleteFiles($content);
            } else {
                unlink($content);
            }
        }
        rmdir($dirPath);
    }
520289
private function _checkDir($filepath, $dirs)
    {
        $directory = dirname($filepath) . DS;
        $_directory = array();
        while (true) {
            // remember the directory to add it to _resource_dir in case we're successful
            $_directory[$directory] = true;
            // test if the directory is trusted
            if (isset($dirs[$directory])) {
                // merge sub directories of current $directory into _resource_dir to speed up subsequent lookup
                $dirs = array_merge($dirs, $_directory);

                return $dirs;
            }
            // abort if we've reached root
            if (!preg_match('#[\\\/][^\\\/]+[\\\/]$#', $directory)) {
                break;
            }
            // bubble up one level
            $directory = preg_replace('#[\\\/][^\\\/]+[\\\/]$#', DS, $directory);
        }

        // give up
        throw new SmartyException("directory '{$filepath}' not allowed by security setting");
    }
583624
public function files($dirname)
    {
        $dirname = $this->path($dirname);

        $directory_contents = glob($dirname . "/*");

        return array_filter($directory_contents, function ($file) {
            return filetype($file) == "file";
        });
    }
42713
public static function mkdir($dirpath)
    {
        if(isset(Yii::$aliases['@static'])){
            $root = Yii::getAlias('@static') . DIRECTORY_SEPARATOR;
        }else{
            $root = Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR;
        }

        $root = preg_replace('/[\\\\\/]/', DIRECTORY_SEPARATOR, $root);
        $dirpath = preg_replace('/[\\\\\/]/', DIRECTORY_SEPARATOR, $dirpath);

        if($dirpath != $root && !file_exists($dirpath)){
            $path = explode(DIRECTORY_SEPARATOR, str_replace($root, '', $dirpath));

            $dirpath = $root . array_shift($path);

            if(!file_exists($dirpath)){
                @mkdir($dirpath);
                @chmod($dirpath, 0777);
            }

            foreach($path as $dir){
                $dirpath .= DIRECTORY_SEPARATOR . $dir;

                if($dir != '.' && $dir != '..'){
                    if(!file_exists($dirpath)){
                        @mkdir($dirpath);
                        @chmod($dirpath, 0777);
                    }
                }
            }
        }

        return $dirpath;
    }
145732
public function getFileList()
    {
        $allfiles = [];

        foreach ($this->filesets as $fs) {
            $ds = $fs->getDirectoryScanner($this->project);

            $files = $ds->getIncludedFiles();

            // We need to store these files keyed by the basedir from DirectoryScanner
            // so that we can resolve the fullpath of the file later.
            if (isset($allfiles[$ds->getBasedir()])) {
                $allfiles[$ds->getBasedir()] = array_merge($allfiles[$ds->getBasedir()], $files);
            } else {
                $allfiles[$ds->getBasedir()] = $files;
            }
        }

        $struc = [];

        foreach ($allfiles as $basedir => $files) {
            foreach ($files as $file) {
                // paths are relative to $basedir above
                $path = strtr(dirname($file), DIRECTORY_SEPARATOR, '/');

                if (!$path || $path == '.') {
                    $path = '/'; // for array index
                }

                $parts = explode('.', basename($file));
                $ext = array_pop($parts);
                if (strlen($ext) == strlen($file)) {
                    $ext = '';
                }

                $f = new PhingFile($basedir, $file);

                $struc[$path][] = [
                    'file' => basename($file),
                    'ext' => $ext,
                    'path' => (($path == '/') ? basename($file) : $path . '/' . basename($file)),
                    'fullpath' => $f->getAbsolutePath()
                ];
            }
        }

        uksort($struc, 'strnatcasecmp');
        foreach ($struc as $key => $ind) {
            usort($ind, [$this, 'sortfiles']);
            $struc[$key] = $ind;
        }

        $tempstruc = $struc;
        $struc = ['/' => $tempstruc['/']];
        $bv = 0;
        foreach ($tempstruc as $key => $ind) {
            $save = $key;
            if ($key != '/') {
                $struc['/'] = $this->setupDirs($struc['/'], explode('/', $key), $tempstruc[$key]);
            }
        }
        uksort($struc['/'], [$this, 'mystrucsort']);

        return $struc;
    }
925864
static public function emptyDir($dirpath)
    {
        foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirpath, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $path) {
            $path->isFile() ? unlink($path->getPathname()) : rmdir($path->getPathname());
        }
    }
504592
public static function getList($folderPath, $thumbPath = null) {

    if (empty($thumbPath)) {
      $thumbPath = $folderPath;
    }

    // Array of image objects to return.
    $response = array();

    $absoluteFolderPath = $_SERVER['DOCUMENT_ROOT'] . $folderPath;

    // Image types.
    $image_types = Image::$defaultUploadOptions['validation']['allowedMimeTypes'];

    // Filenames in the uploads folder.
    $fnames = scandir($absoluteFolderPath);

    // Check if folder exists.
    if ($fnames) {
      // Go through all the filenames in the folder.
      foreach ($fnames as $name) {
        // Filename must not be a folder.
        if (!is_dir($name)) {
          // Check if file is an image.

          if (in_array(mime_content_type($absoluteFolderPath . $name), $image_types)) {
            // Build the image.
            $img = new \StdClass;
            $img->url = $folderPath . $name;
            $img->thumb = $thumbPath . $name;
            $img->name = $name;

            // Add to the array of image.
            array_push($response, $img);
          }
        }
      }
    }

    // Folder does not exist, respond with a JSON to throw error.
    else {
      throw new Exception('Images folder does not exist!');
    }

    return $response;
  }
922746
public function getList(string $path)
    {
        $entity = $this->getEntity($path);

        if (null !== $entity && $entity->file_exists() && $entity->is_dir()) {
            $files = [];
            $changes = $this->getChanges();
            $own = $changes->own($path);

            if (!($entity instanceof VirtualInterface)) {
                $directory = $this->getRoot();
                $directoryPath = $directory->path().'/'.$path;

                $dirHandler = opendir($directoryPath);
                if ($dirHandler) {
                    while (true) {
                        $file = readdir($dirHandler);
                        if (false === $file) {
                            break;
                        } elseif ('.' == $file || '..' == $file) {
                            continue;
                        }

                        $changesKey = ($path ? $path.'/' : '').$file;
                        if (isset($own[$changesKey])) {
                            continue;
                        }
                        $files[$changesKey] = Entity::newInstance($changesKey);
                    }
                    closedir($dirHandler);
                }
            }

            foreach ($own as $changesKey => $file) {
                /* @var $file EntityInterface */
                if ($file instanceof DeletedInterface) {
                    unset($own[$changesKey]);
                }
            }

            $mergedFiles = array_merge($files, $own);
            ksort($mergedFiles);

            $result = array_values($mergedFiles);
        } else {
            $result = null;
        }

        return $result;
    }
1121660
private function scanDirectory($directoryPath)
    {
        if (is_dir($directoryPath)) {
            $files = scandir($directoryPath);
            foreach ($files as $fileName) {
                $filePath = Path::join($directoryPath, $fileName);
                if (is_dir($filePath) && !in_array($fileName, ['.', '..'])) {
                    $this->scanDirectory($filePath);
                } elseif ($this->searchForFileName == strtolower($fileName)) {
                    $this->filePaths[] = $filePath;
                }
            }
        }
    }
927374
protected function get_files( $path ) {
		$filtered_files = array();
		try {
			$files = new RecursiveIteratorIterator(
				new RecursiveDirectoryIterator(
					$path,
					RecursiveDirectoryIterator::SKIP_DOTS
				),
				RecursiveIteratorIterator::CHILD_FIRST
			);
			foreach ( $files as $file_info ) {
				$pathname = self::normalize_directory_separators( substr( $file_info->getPathname(), strlen( $path ) ) );
				if ( $file_info->isFile() && $this->filter_file( $pathname ) ) {
					$filtered_files[] = $pathname;
				}
			}
		} catch ( Exception $e ) {
			WP_CLI::error( $e->getMessage() );
		}

		return $filtered_files;
	}
766022
public function getFilesList($dir)
	{
		$list = [];
		$iterator = Aws\recursive_dir_iterator($dir);
		foreach ($iterator as $filename) {
			$list[] = $filename;
		}
		return $list;
	}
1009210
private function getFileList($path, &$fileList = [], $all = true)
    {
        if (!is_dir($path)) {
            $fileList = [];
            return;
        }
        $data = scandir($path);
        foreach ($data as $one) {
            if ($one == '.' or $one == '..') {
                continue;
            }
            $onePath = $path . DIRECTORY_SEPARATOR . $one;
            $isDir = is_dir($onePath);
            $extName = substr($one, -4, 4);
            if ($isDir == false and $extName == '.php') {
                $fileList[] = $onePath;
            } elseif ($isDir == true and $all == true) {
                $this->getFileList($onePath, $fileList, $all);
            }
        }
    }
116529
public static function list_files($dir, $dirfile = false, $md5 = true, $root = true)
    {
        static $return = [];
        if ($root) {
            $return = [];
        }
        $filepoint = opendir($dir);
        while (($target = readdir($filepoint)) !== false) {
            if ("." == $target || ".." == $target) {
                continue;
            }
            if (is_dir($dir . $target)) {
                self::list_files($dir . $target . '/', $dirfile, $md5, false);
            } else {
                if ($md5) {
                    $file = $dirfile ? $dir . $target : $target;
                    $return[md5_file($dir . $target)] = $file;
                } else {
                    $file = $dirfile ? $dir . $target : $target;
                    $return[] = $file;
                }
            }
        }
        closedir($filepoint);
        return $return;
    }
657522
public function getFiles($dir){
		$dir = self::normalizePath($dir);
	    $files = scandir($dir);
		$results = [];
	    foreach($files as $key => $value){
		    $path = self::normalizePath(self::combinePath($dir, $value));
	        if(!is_dir($path)) {
	        	$results[] = $path;
	        } else if($value != "." && $value != "..") {
	            $results = array_merge($results, getDirContents($path));
	        }
	    }
	    return $results;
	}