<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSURL/fileURL(withPath:isDirectory:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURL(cm)fileURLWithPath:isDirectory:"
  },
  "title" : "fileURL(withPath:isDirectory:)"
}
-->

# fileURL(withPath:isDirectory:)

Initializes and returns a newly created NSURL object as a file URL with a specified path.

```
class func fileURL(withPath path: String, isDirectory isDir: Bool) -> URL
```

## Parameters

`path`

The path that the NSURL object will represent. `path` should be a valid system path, and must not be an empty path. If `path` begins with a tilde, it must first be expanded with [`expandingTildeInPath`](/documentation/Foundation/NSString/expandingTildeInPath). If `path` is a relative path, it is treated as being relative to the current working directory.

`isDir`

A Boolean value that specifies whether `path` is treated as a directory path when resolving against relative path components. Pass <doc://com.apple.documentation/documentation/Swift/true> if the `path` indicates a directory, <doc://com.apple.documentation/documentation/Swift/false> otherwise.

## Return Value

An NSURL object initialized with `path`.

## Discussion

---

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)