SkillAgentSearch skills...

SwiftyRelativePath

Swift equivalent of Ruby's "Pathname.relative_path_from()"

Install / Use

/learn @neoneye/SwiftyRelativePath
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

SwiftyRelativePath

This is a Swift equivalent of Ruby's Pathname.relative_path_from() or Java's 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     |

Usage

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"

Credits

License

MIT License.

View on GitHub
GitHub Stars9
CategoryDevelopment
Updated1y ago
Forks1

Languages

Swift

Security Score

75/100

Audited on Jan 19, 2025

No findings