<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "System",
  "identifier" : "/documentation/System/FilePath/Component",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "System"
    ],
    "preciseIdentifier" : "s:6System8FilePathV9ComponentV"
  },
  "title" : "FilePath.Component"
}
-->

# FilePath.Component

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

```
struct Component
```

## Overview

Components can be one of the special directory components (`.` or `..`)
or a file or directory name. Components are never empty and never
contain the directory separator.

Example:

```
var path: FilePath = "/tmp"
let file: FilePath.Component = "foo.txt"
file.kind == .regular           // true
file.extension                  // "txt"
path.append(file)               // path is "/tmp/foo.txt"
```

## Topics

### Initializers

[`init?(String)`](/documentation/System/FilePath/Component/init(_:))

Create a file path component from a string.

[`init?(platformString: [CInterop.PlatformChar])`](/documentation/System/FilePath/Component/init(platformString:)-2tz4)

Creates a file path component by copying bytes from a null-terminated
platform string. It is a precondition that a null byte indicates the end of
the string. The absence of a null byte will trigger a runtime error.

[`init?(platformString: inout CInterop.PlatformChar)`](/documentation/System/FilePath/Component/init(platformString:)-3mzo3)

[`init?(platformString: String)`](/documentation/System/FilePath/Component/init(platformString:)-8kixy)

[`init?(platformString: UnsafePointer<CInterop.PlatformChar>)`](/documentation/System/FilePath/Component/init(platformString:)-9a3qq)

Creates a file path component by copying bytes from a null-terminated
platform string.

### Instance Properties

[`var `extension`: String?`](/documentation/System/FilePath/Component/extension)

The extension of this file or directory component.

[`var kind: FilePath.Component.Kind`](/documentation/System/FilePath/Component/kind-swift.property)

The kind of this component

[`var stem: String`](/documentation/System/FilePath/Component/stem)

The non-extension portion of this file or directory  component.

[`var string: String`](/documentation/System/FilePath/Component/string)

Creates a string by interpreting the component’s content as UTF-8 on Unix
and UTF-16 on Windows.

### Instance Methods

[`func withPlatformString<Result>((UnsafePointer<CInterop.PlatformChar>) throws -> Result) rethrows -> Result`](/documentation/System/FilePath/Component/withPlatformString(_:))

Calls the given closure with a pointer to the contents of the file path
component, represented as a null-terminated platform string.

### Enumerations

[`enum Kind`](/documentation/System/FilePath/Component/Kind-swift.enum)

Whether a component is a regular file or directory name, or a special
directory `.` or `..`

### Default Implementations

[CustomDebugStringConvertible Implementations](/documentation/System/FilePath/Component/CustomDebugStringConvertible-Implementations)

[CustomStringConvertible Implementations](/documentation/System/FilePath/Component/CustomStringConvertible-Implementations)

[ExpressibleByStringLiteral Implementations](/documentation/System/FilePath/Component/ExpressibleByStringLiteral-Implementations)

## Relationships

### Conforms To

[`ExpressibleByStringLiteral`](/documentation/Swift/ExpressibleByStringLiteral)

[`Encodable`](/documentation/Swift/Encodable)

[`ExpressibleByUnicodeScalarLiteral`](/documentation/Swift/ExpressibleByUnicodeScalarLiteral)

[`Decodable`](/documentation/Swift/Decodable)

[`Equatable`](/documentation/Swift/Equatable)

[`Escapable`](/documentation/Swift/Escapable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Hashable`](/documentation/Swift/Hashable)

[`Copyable`](/documentation/Swift/Copyable)

[`ExpressibleByExtendedGraphemeClusterLiteral`](/documentation/Swift/ExpressibleByExtendedGraphemeClusterLiteral)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Sendable`](/documentation/Swift/Sendable)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)