Swiftpack.co - Package - Ponyboy47/Trailblazer


A type-safe file path library for Apple's Swift language.

I hate going through Foundation's FileManager. I find it to be an ugly API with inconsistent results when used cross platform (Linux support/stability is important to most of the things I use Swift for), and it lacks the type-safety and ease-of-use that most Swift API's are expected to have. So I built TrailBlazer! The first type-safe swift path library built around the lower level C API's (everything else out there is really just a wrapper around Foundation's FileManager).


  • Type safety
    • File paths are different that directory paths
  • Extensibility
    • Everything is based around protocols so that others could create new path types (ie: socket files)
  • Error Handling
    • There are an extensive number of errors so that when something goes wrong you can get the most relevant error message possible
  • Minimal Foundation
    • I avoid using Foundation as much as possible, because it is not as stable on Linux as it is on Apple platforms
    • Currently, I only use Foundation for the Data and Date types

Installation (SPM)

Add this to your Package.swift dependencies:

.package(url: "https://github.com/Ponyboy47/Trailblazer.git", from: "0.1.0")


There are 3 different Path types right now: GenericPath, FilePath, and DirectoryPath

// Paths can be initialized from Strings, Arrays, or Slices
let genericString = GenericPath("/tmp")
let genericArray = GenericPath(["/", "tmp"])
let genericSlice = GenericPath(["/", "tmp", "test"].dropLast())

// FilePaths and DirectoryPaths can be initialized the same as a GenericPath,
// but their initializers are failable.
// The initializers will fail if the path exists and does not match the
// expected type. If the path does not exist, then the object will be created
// successfully

// fails
guard let file = FilePath("/tmp") else {
    print("Path is not a file")
// succeeds
guard let directory = DirectoryPath("/tmp") else {
    print("Path is not a directory")

Getting information about a path:

// Paths conform to the StatDelegate protocol, which means that they use the
// `stat` utility to gather information about the file (ie: size, ownership,
// modify time, etc)
// NOTE: Only paths that exist will have information about them

/// The system id of the path

/// The inode of the path

/// The type of the file

/// The permissions of the file

/// The user id of the user that owns the file

/// The group id of the user that owns the file

/// The device id (if special file)

/// The total size, in bytes

/// The blocksize for filesystem I/O

/// The number of 512B block allocated

/// The last time the file was accessed

/// The last time the file was modified

/// The last time the file had a status change

More to come...

To Do

  • FilePath
    • [ ] Create new files
  • DirectoryPath
    • [ ] Get directory contents
    • [ ] Create new directories
  • GenericPath (AKA all Paths)
    • [ ] Change path ownership
    • [ ] Change path permissions
  • Misc. Additions
    • [ ] Globbing


Stars: 0
Help us keep the lights on


Used By

Total: 0