---
title: "appendingPathComponent(_:isDirectory:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsurl/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.

## Declaration

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

## Mentioned in

Improving performance and stability when accessing the file system

## Return Value

Return Value A new URL with pathComponent appended.

## Discussion

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.

## See Also

### Modifying and Converting a File URL

- [filePathURL](foundation/nsurl/filepathurl.md)
- [fileReferenceURL()](foundation/nsurl/filereferenceurl().md)
- [appendingPathComponent(_:)](foundation/nsurl/appendingpathcomponent(_:).md)
- [appendingPathComponent(_:conformingTo:)](foundation/nsurl/appendingpathcomponent(_:conformingto:).md)
- [appendingPathExtension(_:)](foundation/nsurl/appendingpathextension(_:).md)
- [appendingPathExtension(for:)](foundation/nsurl/appendingpathextension(for:).md)
- [deletingLastPathComponent](foundation/nsurl/deletinglastpathcomponent.md)
- [deletingPathExtension](foundation/nsurl/deletingpathextension.md)
- [resolvingSymlinksInPath](foundation/nsurl/resolvingsymlinksinpath.md)
- [standardizingPath](foundation/nsurl/standardizingpath.md)
- [hasDirectoryPath](foundation/nsurl/hasdirectorypath.md)
