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 implementationUndocumented
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 - Parameters:
-
init(_:)Default implementationUndocumented
Default Implementation
Creates a path from a URL.
Declaration
Swift
public protocol Path: CustomStringConvertible -
Undocumented
Declaration
Swift
public protocol Path: CustomStringConvertible
-
stringExtension methodThe relative or absolute string representation of this path.
Declaration
Swift
public var string: String -
descriptionExtension methodThe relative or absolute string representation of this path.
Declaration
Swift
public var description: String -
baseExtension methodThe base of this path, if it is relative. Otherwise nil.
Declaration
Swift
public var base: DirectoryPath? -
relativeStringExtension methodThe string representation of the relative part of this path, if any.
Declaration
Swift
public var relativeString: String? -
absoluteStringExtension methodThe string representation of the absolute version of this path.
Declaration
Swift
public var absoluteString: String -
nameExtension methodThe main part of this path (the last component).
Declaration
Swift
public var name: String -
extensionExtension methodThe extension of the name (as in
file.extension
).Declaration
Swift
public var `extension`: String? -
nameWithoutExtensionExtension methodThe name without any extension.
Declaration
Swift
public var nameWithoutExtension: String -
absoluteExtension methodIf relative, joins base and relative together. Otherwise returns self.
Declaration
Swift
public var absolute: Self -
parent(nr:)Extension methodGo up
nrdirectories. - parameter nr: How many directories to go up the file tree. Defaults to 1.Declaration
Swift
public func parent(nr levels: Int = 1) -> DirectoryPathParameters
nrHow many directories to go up the file tree. Defaults to 1.
-
hashValueExtension methodThe hash value of the string representation of this path.
Declaration
Swift
public var hashValue: Int
-
exists()Extension methodChecks 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 methodA 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
-
relativeURLExtension methodIf relative, converts this path to a Foundation.URL.
Declaration
Swift
public var relativeURL: URL? -
urlExtension methodConverts this path to a Foundation.URL.
Declaration
Swift
public var url: URL
View on GitHub
Path Protocol Reference