<!--
{
  "availability" : [
    "iOS: 8.0.0 - 27.0.0",
    "iPadOS: 8.0.0 - 27.0.0",
    "macCatalyst: 8.0.0 - 27.0.0",
    "macOS: 10.10.0 - 27.0.0",
    "tvOS: 9.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0",
    "watchOS: 2.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URL/appendingPathComponent(_:isDirectory:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation3URLV22appendingPathComponent_11isDirectoryACSS_SbtF"
  },
  "title" : "appendingPathComponent(_:isDirectory:)"
}
-->

# appendingPathComponent(_:isDirectory:)

Returns a URL by appending the specified path component to self, specifying whether the resulting path is a directory.

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

## Parameters

`pathComponent`

The path component to add.

`isDirectory`

If `true`, the method treats the path component as a directory.

## Return Value

A new URL with the path component appended.

## Discussion

The URL syntax for a directory and for a file at otherwise the same location are slightly different — directory URLs must end in `/`. If you append the path component `second` to the URL `http://www.example.com/first/`, if `isDirectory` is `true`, the resulting URL is `http://www.example.com/first/second/.` If `isDirectory` is `false`, the resulting URL is `http://www.example.com/first/second`.

This difference is particularly important if you resolve another URL against this new URL. For example, the path component `file.html` relative to `http://www.example.com/first/second` is `http://www.apple.com/first/file.html`, whereas relative to `http://www.example.com/first/second/`, it’s `http://www.example.com/first/second/file.html`.

New code should use [`appending(path:directoryHint:)`](/documentation/Foundation/URL/appending(path:directoryHint:)) instead of this method.

---

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)