项目作者: neoneye

项目描述 :
Swift equivalent of Ruby's "Pathname.relative_path_from()"
高级语言: Swift
项目地址: git://github.com/neoneye/SwiftyRelativePath.git
创建时间: 2018-01-20T22:13:55Z
项目社区:https://github.com/neoneye/SwiftyRelativePath

开源协议:MIT License

下载


SwiftyRelativePath

This is a Swift equivalent of Ruby’s Pathname.relative_path_from()
or Java’s Path.relativize().

Example of inputs and outputs:

  1. | Long Path | Relative to Path | Return Value |
  2. |---------------------------|------------------|-------------------|
  3. | /usr/X11/agent/47.gz | /usr/X11 | agent/47.gz |
  4. | /usr/share/man/meltdown.1 | /usr/share/cups | ../man/meltdown.1 |
  5. | /var/logs/x/y/z/log.txt | /var/logs | x/y/z/log.txt |

Usage

  1. import SwiftyRelativePath
  2. let url0 = URL(fileURLWithPath: "/computer/qubit/17")
  3. let url1 = URL(fileURLWithPath: "/computer/lab")
  4. let path = url0.relativePath(from: url1)
  5. // path is "../qubit/17"

Credits

License

MIT License.