recursively scan the directory for any files

@param String $dir - relative to getcwd()
779315
private function scandir($dir) {
        $dir = trim($dir, '/') . '/';
        $absolute = $this->absolute($dir);
        $files = scandir($absolute);

        foreach ($files as $file) {
            // ignore relative references
            if ($file === "." || $file === "..") {
                continue;
            }

            if (is_dir($absolute . $file)) {
                $this->scandir($dir . $file);
            } else {
                // we want the relative path inside the input_dir so we can
                // put the file in the same place in the output_dir
                $path = preg_replace("#^" . Config::get('input_dir') .  "#", "", $dir . $file);
                $this->paths[] = array(
                    'path' => $path
                );
            }
        }
    }
200016
protected function clearDir($dir)
    {
        $iterator = new \DirectoryIterator($dir);
        foreach ($iterator as $file) {

            if ($file->isDir() && !$file->isDot() && !preg_match("~\.~", $file)) {
                $this->clearDir($file->getPathname());
                if (!\rmdir($file->getPathname())) {
                    return false;
                }
            } elseif ($file->isFile()) {
                if (!\unlink($file->getPathname())) {
                    return false;
                }
            }
        }

        return true;
    }
720823
public function loadDir($dir)
    {
        $partialsFiles = scandir($dir);
        $partialsFiles = array_slice($partialsFiles, 2);

        foreach ($partialsFiles as $partialsFile) {

            $partialsFilePath = $dir . $partialsFile;

            if (is_file($partialsFilePath)) {
                $this->loadFile($partialsFilePath);
            } elseif (is_dir($partialsFilePath)) {
                $this->loadDir($partialsFilePath . DIRECTORY_SEPARATOR);
            }
        }
    }
1031523
public function mkdirP($dir)
    {
        $p = [];
        $dirs = explode(DS, $dir);
        foreach ($dirs as $name) {
            $p[] = $name;
            $path = join(DS, $p);
            if ($path === '') {
                continue;
            } elseif (! file_exists($path)) {
                mkdir($path);
            } elseif(! is_dir($path)) {
                throw new Exception("Can not mkdir, this is not directory. -> {$path}");
            }
        }
    }
691664
private function recursiveSearch($directory)
    {
        
		if (is_dir($directory)) {
	    	// We get the list of files and directories.
	    	if (($files = scandir($directory)) !== false) {
	    		
	    		foreach($files as $fd) {
	
	   		 		if (!preg_match("/^\./", $fd) &&  $fd != "ext") {
	   		 			// If it is a directory ...
	   		 			if (is_dir($directory . $fd. "/")) {
	   		 				$this->recursiveSearch($directory . $fd . "/");
		    			// If it is a file ...
	    				} else {
	    					// Retrieve from the file ...
	    					$this->getTranslationsInFile($directory . $fd);
	    				}
	   		 		}
	    			
	    		}
	    	}   	
		}
		
        
    }
210917
private function list_directory( $dir ) {
		$dir_list = array();

		// Only add .mo/.po/.zip files
		foreach ( glob( $dir . '/*.{mo,po,zip}', GLOB_BRACE ) as $file ) {
			$dir_list[] = basename( $file );
		}

		return $dir_list;
	}
405265
protected static function cleanDir($dir) {
		
		if (isset($dir[0])) {
			$dir = trim($dir);
			$dir = ($dir[0] == DIRECTORY_SEPARATOR) ? ltrim($dir, DIRECTORY_SEPARATOR) : $dir;
			$dir = ($dir[strlen($dir)-1] == DIRECTORY_SEPARATOR) ? rtrim($dir, DIRECTORY_SEPARATOR) : $dir;
		}
		
		return $dir;
		
	}
675734
protected function _clean($dir)
    {
        foreach (scandir($dir, SCANDIR_SORT_ASCENDING) as $item) {
            if ($item === '.' || $item === '..') {
                continue;
            }

            $path = $dir . '/' . $item;
            if (is_file($path)) {
                if (time() > filemtime($path)) {
                    @unlink($path);
                }
            } else {
                $this->_clean($path);
            }
        }
    }
616977
public static function rmdir( $dir ) {
		$files = new RecursiveIteratorIterator(
			new RecursiveDirectoryIterator( $dir, RecursiveDirectoryIterator::SKIP_DOTS ),
			RecursiveIteratorIterator::CHILD_FIRST
		);

		foreach ( $files as $fileinfo ) {
			$todo = $fileinfo->isDir() ? 'rmdir' : 'unlink';
			$todo( $fileinfo->getRealPath() );
		}
		rmdir( $dir );
	}
139422
public function mkDirRecursive($dir)
	{
		$parts = explode('/', $dir);
		$path = '';
		while (!empty($parts)) {
			$path .= array_shift($parts);
			try {
				if ($path !== '') $this->mkdir($path);
			} catch (FtpException $e) {
				if (!$this->isDir($path)) {
					throw new FtpException("Cannot create directory '$path'.");
				}
			}
			$path .= '/';
		}
	}
751744
public function find_all_files($dir) 
	{
		$root = scandir($dir);
		if(count($root) == 0) return;

		foreach($root as $value)
		{
			if($value === '.' || $value === '..')
			{
				continue;
			}
			if(is_file("$dir/$value"))
			{
				$result[] = "$dir/$value";
				$this->pages[] = $this->read( "$dir/$value", $value );
				continue;
			}
			foreach($this->find_all_files("$dir/$value") as $value)
			{
				$result[] = $value;
			}
		}
		return $result; 
	}
986180
public function rmdirRecursive($dir) {
		if (is_dir($dir)) {
			foreach (array_diff(scandir($dir), array('.', '..')) as $file) {
				@set_time_limit(30);
				$path = $dir . '/' . $file;
				(is_dir($path)) ? $this->rmdirRecursive($path) : @unlink($path);
			}
			return @rmdir($dir);
		} else if (is_file($dir)) {
			return @unlink($dir);
		}
		return false;
	}
723812
public function mkdir($dir)
    {
        return ($this->isConnected() === true) ? ftp_mkdir($this->getConnection(), $dir) : false;
    }
268768
private function scan($directory, $filename)
    {
        $filename = strtolower($filename);

        foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory)) as $file) {
            if (strtolower($file->getFilename()) == $filename) {
                return $file->getRealPath();
            }
        }

        return null;
    }
202331
public function recursiveScandir(string $dir)
    {
        $contents = array();

        foreach (scandir($dir) as $file) {
            if ($file == '.' || $file == '..') {
                continue;
            }

            $path = $dir.DIRECTORY_SEPARATOR.$file;

            if (is_dir($path)) {
                $contents = array_merge($contents, $this->recursiveScandir($path));
            } else {
                $contents[] = $path;
            }
        }
        return ($contents);
    }
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;
    }
1032
public static function deleteAllFilesInDirectory ($dir) {
        $dirIterator = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS);
        foreach (new \RecursiveIteratorIterator($dirIterator, \RecursiveIteratorIterator::CHILD_FIRST) as $file) {
            $file->isDir() ? rmdir($file) : unlink($file);
        }
    }