improved example
This is a Swift equivalent of Ruby’s Pathname.relative_path_from() or Java’s Path.relativize().
Pathname.relative_path_from()
Path.relativize()
Example of inputs and outputs:
| Long Path | Relative to Path | Return Value | |---------------------------|------------------|-------------------| | /usr/X11/agent/47.gz | /usr/X11 | agent/47.gz | | /usr/share/man/meltdown.1 | /usr/share/cups | ../man/meltdown.1 | | /var/logs/x/y/z/log.txt | /var/logs | x/y/z/log.txt |
import SwiftyRelativePath let url0 = URL(fileURLWithPath: "/computer/qubit/17") let url1 = URL(fileURLWithPath: "/computer/lab") let path = url0.relativePath(from: url1) // path is "../qubit/17"
MIT License.
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
SwiftyRelativePath
This is a Swift equivalent of Ruby’s
Pathname.relative_path_from()
or Java’sPath.relativize()
.Example of inputs and outputs:
Usage
Credits
License
MIT License.