FilePath
public struct FilePath: Path
The path to a file system item which is not a directory or the symbolic link to a directory.
-
Creates an absolute path to a file from (but not including) the root folder through all the directories listed in the array. - Parameter components: The names of the directories in the path, ending with the file name. Each name must not be empty or contain only a ’.’, and any ’..’ must be at the beginning. Cannot be empty.
Declaration
Swift
public init(absolute components: [String])
Parameters
components
The names of the directories in the path, ending with the file name. Each name must not be empty or contain only a ‘.’, and any ‘..’ must be at the beginning. Cannot be empty.
-
Creates a relative path to a file, from the provided base. Each name in the parameter arrays must not be empty or contain only a ’.’, and any ’..’ must be at the beginning. - Parameter base: The names of the directories in the base, in order. - Parameter relative: The names of the directories in the relative part, ending with the file name. Cannot be empty.
Declaration
Swift
public init(base: [String], relative: [String])
Parameters
base
The names of the directories in the base, in order.
relative
The names of the directories in the relative part, ending with the file name. Cannot be empty.
-
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
public 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
public var baseComponents: [String]?
-
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
public var components: [String]
-
Opens the file at ‘path’ for reading.
Returns
A ReadableFile ready to read from the file.Throws
FileSystemError.notFound, .isDirectory, .invalidAccess.Declaration
Swift
public func open() throws -> ReadableFile
Return Value
A ReadableFile ready to read from the file.
-
Opens the file at this path for writing. - Returns: A WritableFile for writing to the new file. - Throws: FileSystemError.notFound, .isDirectory, .invalidAccess.
Declaration
Swift
public func edit() throws -> WritableFile
Return Value
A WritableFile for writing to the new file.
-
Creates a new file at this path for writing. - Parameters: - ifExists: What to do if it already exists: open, throw error or replace. - Throws: FileSystemError.isDirectory, .couldNotCreate, .alreadyExists, .outsideSandbox.
Declaration
Swift
public func create(ifExists: AlreadyExistsOptions) throws -> WritableFile
Parameters
ifExists
What to do if it already exists: open, throw error or replace.
-
Creates a path from a string. If the string begins with a ’/’ it is absolute, otherwise it is relative to the current working directory.
Declaration
Swift
public init(extendedGraphemeClusterLiteral value: String)
-
Creates a path from a string. If the string begins with a ’/’ it is absolute, otherwise it is relative to the current working directory.
Declaration
Swift
public init(stringLiteral value: String)
-
Creates a path from a string. If the string begins with a ’/’ it is absolute, otherwise it is relative to the current working directory.
Declaration
Swift
public init(unicodeScalarLiteral value: String)
-
Declaration
Swift
public static func ==(left: FilePath, right: FilePath) -> Bool
Parameters
lhs
A value to compare.
rhs
Another value to compare.
-
Creates a path from a URL.
Declaration
Swift
public init?(_ url: URL)
Return Value
Path if URL is a file URL and does not have a directory path. Otherwise nil.