<!--
{
  "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/push(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "System"
    ],
    "preciseIdentifier" : "s:6System8FilePathV4pushyyACnF"
  },
  "title" : "push(_:)"
}
-->

# push(_:)

If `other` does not have a root, append each component of `other`. If
`other` has a root, replaces `self` with other.

```
mutating func push(_ other: FilePath)
```

## Discussion

This operation mimics traversing a directory structure (similar to the
`cd` command), where pushing a relative path will append its components
and pushing an absolute path will first clear `self`’s existing
components.

Example:

```
var path: FilePath = "/tmp"
path.push("dir/file.txt") // path is "/tmp/dir/file.txt"
path.push("/bin")         // path is "/bin"
```

---

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)