Returns a relative path based on 2 absolute paths.

@param string $from
@param string $to

@return string
426591
private static function getRelativePath($from, $to)
    {
        $from = explode('/', $from);
        $to = explode('/', $to);
        $relPath = $to;

        foreach ($from as $depth => $dir) {
            // find first non-matching dir
            if (isset($to[$depth]) && $dir === $to[$depth]) {
                // ignore this directory
                array_shift($relPath);
            } else {
                // get number of remaining dirs to $from
                $remaining = count($from) - $depth;
                if ($remaining > 1) {
                    // add traversals up to first matching dir
                    $padLength = (count($relPath) + $remaining - 1) * -1;
                    $relPath = array_pad($relPath, $padLength, '..');
                    break;
                } else {
                    $relPath[0] = './'.$relPath[0];
                }
            }
        }

        return implode('/', $relPath);
    }
1068792
private function copyDir($from, $to)
    {
        mkdir($to, 0777, true);
        
        $items = new FilesystemIterator($from);

        foreach ($items as $item)
        {
            $pattern = preg_quote($from, "/");
            $Key = preg_replace("/^{$pattern}/", "", $item);

            $subFrom = strval($item);
            $subTo   = $to.$Key;
            
            if (filetype($item) == 'dir')
            {
                $this->copyDir($subFrom, $subTo);
            } else {
                $this->copyFile($subFrom, $subTo);
            }
        }

        return true;
    }
376857
public function rename($from, $to) {
		$path1 = $this->escapePath($from);
		$path2 = $this->escapePath($to);
		$output = $this->execute('rename ' . $path1 . ' ' . $path2);
		return $this->parseOutput($output, $to);
	}
1049531
public function moveFolder( $from, $to )
	{
		$this->connection->checkConnection();
		if( ftp_size( $this->connection->getResource(), $from ) != -1 )
			throw new RuntimeException( 'Folder "'.$from.'" is not existing.' );
		return @ftp_rename( $this->connection->getResource(), $from, $to );
	}
993860
public function rename($from, $to)
    {
        $url = (array) parse_url($to) + [
            'path' => '',
            'host' => ''
        ];

        $destinationBucket = $url['host'];
        $destinationPath = substr($url['path'], 1);

        $this->dir_opendir($from, []);
        foreach ($this->directoryIterator as $file) {
            $name = $file->name();
            $newPath = str_replace($this->file, $destinationPath, $name);

            $obj = $this->bucket->object($name);
            try {
                $obj->rename($newPath, ['destinationBucket' => $destinationBucket]);
            } catch (ServiceException $e) {
                // If any rename calls fail, abort and return false
                return false;
            }
        }
        return true;
    }
165468
public String getRelativePath(File from, File to) {
        Path fromPath = Paths.get(from.getPath()).normalize().toAbsolutePath();
        Path toPath = Paths.get(to.getPath()).normalize().toAbsolutePath();
        return fromPath.relativize(toPath).toString().replace('\\', '/');
    }
19961
public function copyTo(FileNode $from, FileNode $to)
    {
        $mountManager = new MountManager([
            'from' => $from->getFilesystem(),
            'to'   => $to->getFilesystem(),
        ]);

        $this->log(LogLevel::INFO, "Copying file from: '{from}', to: '{to}'", [
            'from' => $from,
            'to'   => $to,
        ]);
        if (!$mountManager->copy('from://' . $from->getPath(), 'to://' . $to->getPath())) {
            throw new TransferFailedException($from, $to);
        }

        return $to;
    }
1016155
public function copy($from, $to)
    {
        $from = ltrim($from, "/");
        $to   = ltrim($to, "/");

        if (!$this->exists($from)) {
            $path = $this->bucket . "/" . $from;
            throw new ExceptionStorage("Object {$path} Not found", static::E_NOT_IS_DIR);
        }

        if ($this->exists($to)) {
            $path = $this->bucket . "/" . $to;
            throw new ExceptionStorage("Object {$path} exists");
        }

        // Copia Object
        $this->clientS3->copyObject(array(
            'Bucket'     => $this->bucket,
            'Key'        => $to,
            'CopySource' => $this->bucket . '/' . rawurlencode($from),
            'ACL'        => static::ACL_PUBLIC_READ,
            'MetadataDirective' => 'COPY',
        ));

        $pathFrom = trim($from, '/') . '/';

        $iterator = $this->clientS3->getIterator('ListObjects', array(
            'Bucket' => $this->bucket,
            'Prefix' => $pathFrom,
        ));

        foreach ($iterator as $object)
        {
            $pattern = preg_quote($pathFrom, "/");
            $Key = preg_replace("/^{$pattern}/", "", $object['Key']);

            if (!empty($Key))
            {
                $pattern = preg_quote($pathFrom, "/");
                $Key = preg_replace("/^{$pattern}/", "", $object['Key']);

                $origem  = $this->bucket . '/' . $object['Key'];
                $destino = trim($to, "/") . "/" . $Key;

                // Copia Object
                $this->clientS3->copyObject(array(
                    'Bucket'     => $this->bucket,
                    'Key'        => $destino,
                    'CopySource' => $origem,
                    'ACL'        => static::ACL_PUBLIC_READ,
                    'MetadataDirective' => 'COPY'
                ));
            }
        }

        return true;
    }
1124219
public function createLink($from, $to)
    {
        if (File::exists($from)) {
            if (!File::exists($to)) {
                try {
                    symlink($from, $to);
                } catch (\Exception $e) {
                    throw new \Exception("Cannot create symlink from $from to $to");
                }
            }
        }
    }
220713
public function search(string $from, string $to) : array
    {
        if (!isset($this->nodes[$from]) || !isset($this->nodes[$to])) {
            throw new \UnexpectedValueException("node {$from} or node {$to} does not exist");
        }
        // initialization
        $nodes      = array_keys($this->nodes);
        $distance   = [];
        $parent     = [];
        $visit      = [];

        foreach ($this->nodes as $key => $value) {
            $distance[$key] = $this->total_cost +1;
        }
        $distance[$from] = 0;

        // set start node
        foreach ($this->nodes as $key => $val) {
            $parent[$key] = null;
        }
        foreach ($this->nodes[$from] as $key => $val) {
            $distance[$key] = $this->nodes[$from][$key];
            $parent[$key]   = $from;
        }
        $visit[] = $from;

        // search shortest route
        for (;;) {
            $min_distance   =   $this->total_cost + 1;
            $node           =   null;
            foreach (array_diff($nodes, $visit) as $key) {
                if ($distance[$key] < $min_distance) {
                    $node           =   $key;
                    $min_distance   =   $distance[$key];
                }
            }
            if ($node === $to) {
                break;
            } elseif (is_null($node)) {
                throw new \UnexpectedValueException("path from {$from} to {$to} does not exist");
            }
            foreach (array_diff(array_keys($this->nodes[$node]), $visit) as $key) {
                if ($distance[$key] > $distance[$node] + $this->nodes[$node][$key]) {
                    $distance[$key] = $distance[$node] + $this->nodes[$node][$key];
                    $parent[$key]   = $node;
                }
            }
            $visit[] = $node;
        }

        $result = [];
        for (;;) {
            $result[] = $node;
            if ($node === $from) {
                break;
            }
            $node = $parent[$node];
        }
        return array_reverse($result);
    }
765174
public static function getTravelPath($from, $to)
    {
        $from = explode(DS, $from);
        $to = explode(DS, $to);

        $relPath = $to;

        foreach ($from as $depth => $dir) {
            // find first non-matching dir
            if ($dir === $to[$depth]) {
                // ignore this directory
                array_shift($relPath);
            } else {
                // get number of remaining dirs to $from
                $remaining = count($from) - ($depth - 1);
                if ($remaining > 1) {
                    // add traversals up to first matching dir
                    $padLength = (count($relPath) + $remaining - 1) * -1;
                    $relPath = array_pad($relPath, $padLength, '..');
                    break;
                } else {
                    $relPath[0] = './'.$relPath[0];
                }
            }
        }

        return implode('/', $relPath);
    }
837409
public function move($from, $to)
    {
        event(new Events\FileMoving($from, $to));
        $moved = $this->disk()->move($from, $to);
        event(new Events\FileMoved($from, $to, $moved));

        return $moved;
    }
680197
public function moveDataFile($from, $to)
    {
        if (str_contains($from, '*.')) {
            $this->moveFilesWildcard($from, $to);

            return;
        }

        if (file_exists($from = $this->dataDir($from))) {
            $this->mkDir(dirname($to = $this->dataDir($to)));

            rename($from, $to);
        }
    }
1044503
public function copy($from, $to)
    {
        $pathFrom = $this->pathRoot.ltrim($from, "/");
        $pathTo   = $this->pathRoot.ltrim($to, "/");

        if (is_dir($pathFrom)) {
            return $this->copyDir($pathFrom, $pathTo);
        } else {
            return $this->copyFile($pathFrom, $pathTo);
        }
    }
80687
protected function publishDirectory($from, $to)
    {
        $this->moveManagedFiles(new MountManager([
            'from' => new \League\Flysystem\Filesystem(new Local($from)),
            'to' => new \League\Flysystem\Filesystem(new Local($to))
        ]));

        $this->status($from, $to, 'Directory');
    }
131120
public function move(string $from, string $to, array $config = []): bool
    {
        list($prefixFrom, $pathFrom) = $this->getPrefixAndPath($from);
        list($prefixTo, $pathTo) = $this->getPrefixAndPath($to);

        if ($prefixFrom === $prefixTo) {
            $fs = $this->getFileSystem($prefixFrom);
            $renamed = $fs->rename($pathFrom, $pathTo);

            unset($prefixFrom, $pathFrom, $prefixTo);

            if ($renamed && isset($config['visibility'])) {
                return $fs->setVisibility($pathTo, $config['visibility']);
            }

            unset($fs, $pathTo);

            return $renamed;
        }

        if ($this->copy($from, $to, $config)) {
            return $this->delete($from);
        }

        return false;
    }
1184355
static function  rebasedFilename($file,$from,$to) {
		if (!Strings::startsWith($file, $from)) {
			throw new \InvalidArgumentException("File $file is not in directory $from");
		}
		$secondPart=Strings::substring($file, Strings::length($from));
		if ($secondPart[0]=="/") $secondPart=substr($secondPart,1);
		$newPath=$to."/".$secondPart;
		return $newPath;
	}