<!--
{
  "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/lastComponent",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "System"
    ],
    "preciseIdentifier" : "s:6System8FilePathV13lastComponentAC0E0VSgvp"
  },
  "title" : "lastComponent"
}
-->

# lastComponent

Returns the final component of the path.
Returns `nil` if the path is empty or only contains a root.

```
var lastComponent: FilePath.Component? { get }
```

## Discussion

Note: Even if the final component is a special directory
(`.` or `..`), it will still be returned. See `lexicallyNormalize()`.

Examples:

- Unix:
  - `/usr/local/bin/ => bin`
  - `/tmp/foo.txt    => foo.txt`
  - `/tmp/foo.txt/.. => ..`
  - `/tmp/foo.txt/.  => .`
  - `/               => nil`
- Windows:
  - `C:\Users\                    => Users`
  - `C:Users\                     => Users`
  - `C:\                          => nil`
  - `\Users\                      => Users`
  - `\\?\UNC\server\share\bar.exe => bar.exe`
  - `\\server\share               => nil`
  - `\\?\UNC\server\share\        => nil`

---

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)