Join $file to $dir path, and clean up any excess slashes.

@param string $dir
@param string $file
349737
public static function pathJoin($dir, $file) {
        if (empty($dir) || empty($file)) {
            return self::getRelativePath($dir . $file);
        }
        return self::getRelativePath($dir . '/' . $file);
    }
371098
public static function cleanDir($dir, $need = true)
	{
		if (!file_exists($dir)) {
			return true;
		}

		if(is_dir($dir)){
			$files = glob($dir . DIRECTORY_SEPARATOR . '*', GLOB_MARK ); //GLOB_MARK adds a slash to directories returned

			foreach($files as $file) {
				static::rm($file, $need);
			}
		}

		return true;
	}
925365
public function loadPhpFiles($dir)
    {
        $files = Finder::create()->files()->name('*.php')->in($dir);
        foreach ($files as $file) {
            $this->loadFile($file->getRealpath());
        }

    }
964483
protected function expandPath(
        /*# string */ $file,
        /*# string */ $path
    )/*# : string */ {
        // relative path found
        if (false !== strpos($file, './')) {
            // remember working dir
            $old = getcwd();

            // change to current file's directory
            chdir(dirname(realpath($path)));

            // expand file path
            $file = realpath($file);

            // back to working dir
            chdir($old);
        }

        return $file;
    }
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 .= '/';
		}
	}
393928
static function setAppPath($dir)
    {
        if (is_dir($dir))
        {
            self::$app_path = $dir;
        }
        else
        {
            \Swoole\Error::info("fatal error", "app_path[$dir] is not exists.");
        }
    }
107296
private function AddFileToResult($directory, $file) {
        if (array_key_exists($directory, $this->FileList)) {
            array_push($this->FileList[$directory], $file);
            return;
        }
        //array_push($this->FileList, $directory);
        $this->FileList[$directory] = [$file];
    }
777903
private static void rmDir(File dir) {
        for (File file: dir.listFiles()) {
            if (file.isDirectory()) {
                rmDir(file);
            } else {
                if (!file.delete()) {
                    logger.warn("Can't delete file " + file);
                }
            }
        }
        if (!dir.delete()) {
            logger.warn("Can't delete dir " + dir);
        }
    }
748766
public static function delete($file) {
		if(!file_exists($file))
			return false;

		if(is_dir($file))
			static::deleteDir($file);
		else
			unlink($file);

		return true;
	}
16707
private function _rrmdir($dir)
    {
        if ($handle = opendir($dir)) {
            while (false !== ($file = readdir($handle))) {
                if ($file != '.' && $file != '..') {
                    if (is_dir($dir . '/' . $file)) {
                        $this->_rrmdir($dir . '/' . $file);
                        rmdir($dir . '/' . $file);
                    } else {
                        unlink($dir . '/' . $file);
                    }
                }
            }
            closedir($handle);
        }
    }
178443
public static void deleteFileOrDirectory(File file) {
    if (!file.isDirectory()) {
      file.delete();
      return;
    }

    if (file.list().length == 0) { //Nothing under directory. Just delete it.
      file.delete();
      return;
    }

    for (String temp : file.list()) { //Delete files or directory under current directory.
      File fileDelete = new File(file, temp);
      deleteFileOrDirectory(fileDelete);
    }
    //Now there is nothing under directory, delete it.
    deleteFileOrDirectory(file);
  }
105913
private function constructExamplePath(string $directory, string $file): string
    {
        return rtrim($directory, '\\/') . DIRECTORY_SEPARATOR . $file;
    }
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);
        }
    }
504963
protected function _makeDirectory( $directory )
    {
        try
        {
            if ( !is_dir( $directory ) && !is_file( $directory ) && !is_link( $directory ) )
            {
                mkdir( $directory, 0755, true );
            }
        }
        catch ( \Exception $e )
        {
            $this->error( $e->getMessage() );
            die;
        }
    }
415573
public static void deleteRecursive(@Nonnull File dir) throws IOException {
        deleteRecursive(fileToPath(dir), PathRemover.PathChecker.ALLOW_ALL);
    }
802697
private function load($file, $dir = '')
    {
        $path = config_path().'/'.$dir;
        $handle = opendir($path);
        $ignore = ['.', '..'];
        while ($f = readdir($handle)) {
            if (!in_array($f, $ignore)) {
                if (is_dir($path.$f)) {
                    if (file_exists($path.$f.'/'.$file.'.php')) {
                        return $this->load($file, $f);
                    }
                } else {
                    $filename = explode('.', $f)[0];
                    if ($filename == $file) {
                        return require $path.'/'.$f;
                    }
                }
            }
        }
        closedir($handle);

        return false;
    }
44861
static function isFileInDir($file,$dir) {
		if (!Strings::endsWith($dir, "/")) $dir.="/";
		return Strings::startsWith($file, $dir);
	}