Swiftpack.co - Package - Kitura-Next/FileKit
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.


APIDoc Apache 2 Slack Status


Resolves commonly used paths, including the project, executable and working directories.

Swift version

Requires Swift 5.1 or newer. You can download the Swift binaries by following this link.
Compatibility with other Swift versions is not guaranteed.


Add dependencies

Add FileKit to the dependencies within your application's Package.swift file. Substitute "x.x.x" with the latest FileKit release.

.package(url: "https://github.com/Kitura-Next/FileKit.git", from: "x.x.x")

Add FileKit to your target's dependencies:

.target(name: "example", dependencies: ["FileKit"]),

Import package

import FileKit

You will also need to import the Foundation package if you're handling URLs:

import Foundation

Supported Paths

Path to Executable Folder

Points to the folder containing the project executable.

For example, when running an executable called MySwiftProject within Xcode the executable folder string would be "/Users/username/MySwiftProject/.build/debug", when running the same project from the command line this would be "/Users/username/MySwiftProject/.build/x86_64-apple-macosx10.10/debug".

  /// Executable Folder String
  let stringUrl = FileKit.executableFolder

  /// Executable Folder URL
  let urlObject = FileKit.executableFolderURL

  /// Executable File
  let urlObject = FileKit.executableURL

Note, the executableURL will be different when running inside Xcode versus running from the command line. For example, when running an executable called MySwiftProject:

  • Running on the command line - file:///Users/username/MySwiftProject/.build/x86_64-apple-macosx10.10/debug/MySwiftProject
  • Running within Xcode - file:///Users/username/Library/Developer/Xcode/DerivedData/MySwiftProject-fjgfjmxrlbhzkhfmxdgeipylyeay/Build/Products/Debug/MySwiftProject.

Path to Project Folder

Points to the directory containing the Package.swift of the project (as determined by traversing up the directory structure starting at the directory containing the executable), or if no Package.swift is found then the directory containing the executable.

  /// Absolute path to the project's root folder
  let stringUrl = FileKit.projectFolder

  /// URL to the project's root folder
  let urlObject = FileKit.projectFolderURL

Path to Working Directory

Provides the standardized working directory, while accounting for environmental changes. When running in Xcode, this returns the directory containing the Package.swift of the project, while outside Xcode it returns the current working directory.

  /// Absolute path to the present working directory
  let stringUrl = FileKit.workingDirectory

  /// URL to the project's root folder
  let urlObject = FileKit.workingDirectoryURL

Native Swift File Utilities

Note. As this is native Swift functionality you can use this without importing FileKit.

  /// URL pointing to the current source file when it was compiled.
  let stringUrl = URL(fileURLWithPath: #file)

API documentation

For more information visit our API reference.


We love to talk server-side Swift, and Kitura. Join our Slack to meet the team!


This library is licensed under Apache 2.0. Full license text is available in LICENSE.


Stars: 0



0.0.4 - 2020-12-12T06:02:17

  • Update testing to include Swift 5.3.1
  • Remove support for Swift 4

0.0.3 - 2020-10-28T11:24:19