---
title: "appendingPathComponent(_:isDirectory:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/url/appendingpathcomponent(_:isdirectory:)"
---

# appendingPathComponent(_:isDirectory:)

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

## Declaration

```swift
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

Return Value A new URL with the path component appended.

## Discussion

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:) instead of this method.

## See Also

### Adding path components

- [append(path:directoryHint:)](foundation/url/append(path:directoryhint:).md)
- [append(component:directoryHint:)](foundation/url/append(component:directoryhint:).md)
- [appendPathComponent(_:)](foundation/url/appendpathcomponent(_:).md)
- [appendPathComponent(_:isDirectory:)](foundation/url/appendpathcomponent(_:isdirectory:).md)
- [appending(path:directoryHint:)](foundation/url/appending(path:directoryhint:).md)
- [appending(component:directoryHint:)](foundation/url/appending(component:directoryhint:).md)
- [appendingPathComponent(_:)](foundation/url/appendingpathcomponent(_:).md)
- [append(components:directoryHint:)](foundation/url/append(components:directoryhint:).md)
- [appending(components:directoryHint:)](foundation/url/appending(components:directoryhint:).md)
- [appendPathComponent(_:conformingTo:)](foundation/url/appendpathcomponent(_:conformingto:).md)
- [appendingPathComponent(_:conformingTo:)](foundation/url/appendingpathcomponent(_:conformingto:).md)
