Path

public protocol Path: CustomStringConvertible

The location of an item which may or may not exist in the local file system. It is either a DirectoryPath or a FilePath.

  • The individual parts of the absolute version of this path, from (but not including) the root folder. Any ’..’ not at the beginning have been resolved, and there are no empty parts or only ’.’.

    Declaration

    Swift

    var components: [String]
  • The individual parts of the relative part (if any) of this path. Any ’..’ not at the beginning have been resolved, and there are no empty parts or only ’.’. If this exists, then so do baseComponents.

    Declaration

    Swift

    var relativeComponents: [String]?
  • The individual parts of the base part (if any) of this path, from (but not including) the root folder. Any ’..’ not at the beginning have been resolved, and there are no empty parts or only ’.’. If this exists, then so do relativeComponents.

    Declaration

    Swift

    var baseComponents: [String]?
  • Undocumented

    Declaration

    Swift

    public protocol Path: CustomStringConvertible
  • init(base:relative:) Default implementation

    Undocumented

    Default Implementation

    Creates a relative path from two strings.

    • Parameters:
      • base: The path to the directory this path is relative to. If it does not begin with a ’/’ it will be appended to the current working directory.
      • relative: The relative path. It doesn’t matter if this begins with a ’/’.

    Declaration

    Swift

    public protocol Path: CustomStringConvertible
  • init(_:) Default implementation

    Undocumented

    Default Implementation

    Creates a path from a URL.

    Declaration

    Swift

    public protocol Path: CustomStringConvertible
  • Undocumented

    Declaration

    Swift

    public protocol Path: CustomStringConvertible
  • string Extension method

    The relative or absolute string representation of this path.

    Declaration

    Swift

    public var string: String
  • description Extension method

    The relative or absolute string representation of this path.

    Declaration

    Swift

    public var description: String
  • base Extension method

    The base of this path, if it is relative. Otherwise nil.

    Declaration

    Swift

    public var base: DirectoryPath?
  • relativeString Extension method

    The string representation of the relative part of this path, if any.

    Declaration

    Swift

    public var relativeString: String?
  • absoluteString Extension method

    The string representation of the absolute version of this path.

    Declaration

    Swift

    public var absoluteString: String
  • name Extension method

    The main part of this path (the last component).

    Declaration

    Swift

    public var name: String
  • extension Extension method

    The extension of the name (as in file.extension).

    Declaration

    Swift

    public var `extension`: String?
  • nameWithoutExtension Extension method

    The name without any extension.

    Declaration

    Swift

    public var nameWithoutExtension: String
  • absolute Extension method

    If relative, joins base and relative together. Otherwise returns self.

    Declaration

    Swift

    public var absolute: Self
  • parent(nr:) Extension method

    Go up nr directories. - parameter nr: How many directories to go up the file tree. Defaults to 1.

    Declaration

    Swift

    public func parent(nr levels: Int = 1) -> DirectoryPath

    Parameters

    nr

    How many directories to go up the file tree. Defaults to 1.

  • hashValue Extension method

    The hash value of the string representation of this path.

    Declaration

    Swift

    public var hashValue: Int
  • exists() Extension method

    Checks if this path points to an existing item in the local filesystem. - Note: Does not check if this path points to the correct type of item (file or directory).

    If this is a symbolic link which points to a non-existing path, then the result is false.

    Declaration

    Swift

    public func exists() -> Bool
  • resolvingSymlinks() Extension method

    A path referring to the same item in the file system, where all symbolic links have been resolved. Components of this path which do not exist are returned unchanged.

    Declaration

    Swift

    public func resolvingSymlinks() -> Self
  • relativeURL Extension method

    If relative, converts this path to a Foundation.URL.

    Declaration

    Swift

    public var relativeURL: URL?
  • url Extension method

    Converts this path to a Foundation.URL.

    Declaration

    Swift

    public var url: URL