Get file/directory modification time

If this is a newly created file/dir, we will set the time to 'now'

@param	string	$dir	path to file
@return	array	filemtime/filemdate
435689
protected function _get_mod_time($dir)
	{
		// filemtime() may return false, but raises an error for non-existing files
		$date = file_exists($dir) ? getdate(filemtime($dir)) : getdate($this->now);

		return array(
			'file_mtime' => ($date['hours'] << 11) + ($date['minutes'] << 5) + $date['seconds'] / 2,
			'file_mdate' => (($date['year'] - 1980) << 9) + ($date['mon'] << 5) + $date['mday']
		);
	}
766022
public function getFilesList($dir)
	{
		$list = [];
		$iterator = Aws\recursive_dir_iterator($dir);
		foreach ($iterator as $filename) {
			$list[] = $filename;
		}
		return $list;
	}
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;
	}
1100621
public function getMakefiles($dir)
    {
        $finder = new Finder();
        $finder->in($dir)
               ->files()
               ->depth('< 1')
               ->name('*.make*');
        return $finder;
    }
358669
protected static function get_file_list($directory) {
        global $CFG;
        $directoryroot = $CFG->dirroot;
        $finalfiles = array();
        if (is_dir($directory)) {
            if ($handle = opendir($directory)) {
                $files = scandir($directory);
                foreach ($files as $file) {
                    if ($file != '.' && $file != '..') {
                        // Ignore the file if it is external to the system.
                        if (strrpos($directory, $directoryroot) !== false) {
                            $location = substr($directory, strlen($directoryroot));
                            $name = substr($file, 0, -4);
                            $finalfiles[$name] = $location  . '/' . $file;
                        }
                    }
                }
            }
        }
        return $finalfiles;
    }
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; 
	}
41566
public function uploadDir($dir)
	{
		$this->uploadDir = $dir;
		if(! $this->hasTrailingSlash())
		{
			$this->uploadDir .= "/";
		}

		return $this;
	}
1201531
public static function ls($dir): array
    {
        $contents = [];

        $flags = \FilesystemIterator::KEY_AS_PATHNAME
            | \FilesystemIterator::CURRENT_AS_FILEINFO
            | \FilesystemIterator::SKIP_DOTS;

        $dirIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, $flags));

        foreach ($dirIterator as $path => $fi) {
            $contents[] = $path;
        }

        natsort($contents);
        return $contents;
    }
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;
		
	}
667151
public function modified()
    {
        $path = $this->get('filepath');

        if (!file_exists($path)) {
            return null;
        }

        return filemtime($path) ?: null;
    }
311597
public function chdir($dir) {
		$this->connectIfNeeded();
		$this->handle->chdir($dir);
		$this->onFolderChanged(new Event(['sender' => $this, 'data' => $dir]));
		try {
			$cwd = $this->pwd();
		} catch (FtpException $ex) {
			$cwd = $dir;	
		}
		return $cwd;
	}
549866
private function getFolderContent($dir)
    {
        $finder = Finder::create()
            ->ignoreVCS(false)
            ->ignoreDotFiles(false)
            ->depth(0)
            ->in($dir);

        return iterator_to_array($finder);
    }
1154642
protected function getCachePath($dir)
    {
        $filepath = $this->getCacheName($dir);

        return $this->getAutoLoader()->getCachePath() . $filepath;
    }
844447
public static function fileMakeTime($path)
    {
        if (self::isPhar($path) === false) {
            return filemtime($path);
        }

        return filemtime(self::getPharPath($path));
    }
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);
    }
139806
public function setDir($dir)
    {
        if (!is_dir($dir) && !@mkdir($dir, 0755, true)) {
            $message = sprintf('Failed to create directory "%s"', $dir);
            ($e = error_get_last()) && $message .= ': ' . $e['message'];
            throw new \RuntimeException($message);
        }
        $this->dir = realpath($dir);
        return $this;
    }
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 );
	}