Latest 1.0.2
License MIT
Platforms ios 8.0, osx 10.9, tvos 9.0

Build Status

SimplePath is a library for working with file paths in Swift. It borrows heavily from the path libraries of other languages such as Go, PHP, C and Perl, and runtimes such as Node.js.

This library doesn’t try to hide the fact that file paths are strings. Most of its functions take strings as arguments and return strings.



Builds a path string by joining components, adding directory separators where necessary.

let path = Path.join([

// path -> /var/www/website/robots.txt


Returns all components of a given path.

let components = Path.split("/storage/images/0001.jpg")

// components -> [
//   "/",
//   "storage",
//   "images",
//   "0001.jpg"
// ]


Returns the last component of a path. Usually a file name.

let base = Path.basename("assets/images/logo.png")

// base -> "logo.png"
let base = Path.basename("assets/images/logo.png", ext: "png")

// base -> "logo"


Returns the parent directory of a path.

let dir = Path.dirname("/var/data/map.bin")

// dir -> "/var/data"


Gets the extension of a path.

let ext = Path.extname("assets/sfx/drumroll.wav")

// ext -> "wav"
let ext = Path.extname("assets/sfx")

// ext -> nil


Builds a path, given named elements of the path.

let path = Path.format([
    .dir:  "assets/icons",
    .base: "settings.png"

// path -> "assets/icons/settings.png"
let path = Path.format([
    .dir:  "assets/vector",
    .base: "logo"
    .ext:  "svg"

// path -> "assets/vector/logo.svg"

Path.isAbsolute(path) and Path.isRelative(path)

Can be used for checking if a path is absolute or relative.

Path.isAbsolute("/var/logs/test.log") // -> true
Path.isRelative("cache/images/1.bin") // -> true


Returns true if the path exists.

Path.exists("/path/to/existing/file.txt") // -> true


Returns true if the path exists and is a regular file.

Path.isFile("/path/to/existing/file.txt") // -> true


Returns true if the path exists and is a directory.

Path.isDir("/path/to/existing/dir") // -> true


If you think SimplePath is missing important functionalty I suggest you follow these steps:

  1. Implement such functionality as an extension.
  2. And if you believe that the functionality is highly reusable, feel free to contribute it back to the project by opening a pull request.


This library is licensed under the MIT license.

Latest podspec

    "name": "SimplePath",
    "version": "1.0.2",
    "summary": "A Swift library for working with file paths",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Ramon Torres": "[email protected]"
    "social_media_url": "",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "tvos": "9.0"
    "source": {
        "git": "",
        "tag": "1.0.2"
    "source_files": "Sources/*.swift",
    "pushed_with_swift_version": "4.0"

Pin It on Pinterest

Share This