FilePath

    Represents a location in the file system.

    FilePath.swift:44
    struct FilePath

    This structure recognizes directory separators (e.g. /), roots, and requires that the content terminates in a NUL (0x0). Beyond that, it does not give any meaning to the bytes that it contains. The file system defines how the content is interpreted; for example, by its choice of string encoding.

    On construction, FilePath will normalize separators by removing redundant intermediary separators and stripping any trailing separators. On Windows, FilePath will also normalize forward slashes / into backslashes \, as preferred by the platform.

    The code below creates a file path from a string literal, and then uses it to open and append to a log file:

    let message: String = "This is a log message."
    let path: FilePath = "/tmp/log"
    let fd = try FileDescriptor.open(path, .writeOnly, options: .append)
    try fd.closeAfter { try fd.writeAll(message.utf8) }

    File paths conform to the doc://com.apple.documentation/documentation/swift/equatable and doc://com.apple.documentation/documentation/swift/hashable protocols by performing the protocols’ operations on their raw byte contents. This conformance allows file paths to be used, for example, as keys in a dictionary. However, the rules for path equivalence are file-system–specific and have additional considerations like case insensitivity, Unicode normalization, and symbolic links.

    Citizens in SystemPackage

    Conformances

    Types

    • struct Component

      Represents an individual, non-root component of a file path.

    • struct ComponentView

      A bidirectional, range replaceable collection of the non-root components that make up a file path.

    • struct Root

      Represents a root of a file path.

    Type members

    Show obsolete interfaces (6)

    Hide obsolete interfaces

    Instance members

    Type features

    Extension in WebURLSystemExtras

    Type members