<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSURL/appendingPathComponent(_:isDirectory:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURL(im)URLByAppendingPathComponent:isDirectory:"
  },
  "title" : "appendingPathComponent(_:isDirectory:)"
}
-->

# appendingPathComponent(_:isDirectory:)

Returns a new URL by appending a path component to the original URL, along with a trailing slash if the component is a directory.

```
func appendingPathComponent(_ pathComponent: String, isDirectory: Bool) -> URL?
```

## Parameters

`pathComponent`

The path component to add to the URL.

`isDirectory`

If <doc://com.apple.documentation/documentation/Swift/true>, a trailing slash is appended after `pathComponent`.

## Return Value

A new URL with `pathComponent` appended.

## Discussion

If the original URL does not end with a forward slash and `pathComponent` does not begin with a forward slash, a forward slash is inserted between the two parts of the returned URL, unless the original URL is the empty string.

---

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)