Git Product home page Git Product logo

filekit's Introduction

Kitura

APIDoc Build Status - Master macOS Linux Apache 2 Slack Status

FileKit

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

Version

The latest release of FileKit (0.x.x) runs on Swift 5.2 and newer, on both macOS and Ubuntu Linux.

Usage

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/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.

Community

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

License

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

filekit's People

Contributors

dannys42 avatar djones6 avatar helenmasters avatar saihemak avatar shihabmehboob avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

filekit's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.