Resolves commonly used paths, including the project, executable and working directories.
The latest release of FileKit
(0.x.x) runs on Swift 5.2 and newer, on both macOS and Ubuntu Linux.
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/FileKit.git", from: "x.x.x")
Add FileKit
to your target's dependencies:
.target(name: "example", dependencies: ["FileKit"]),
import FileKit
You will also need to import the Foundation
package if you're handling URLs:
import Foundation
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
.
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
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
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)
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.