---
title: "fileURL(withPath:isDirectory:relativeTo:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsurl/fileurl(withpath:isdirectory:relativeto:)"
---

# fileURL(withPath:isDirectory:relativeTo:)

Initializes and returns a newly created file NSURL referencing the local file or directory at path, relative to a base URL.

## Declaration

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

## Mentioned in

Improving performance and stability when accessing the file system

## See Also

### Creating a URL object

- [init(string:)](foundation/nsurl/init(string:).md)
- [init(string:encodingInvalidCharacters:)](foundation/nsurl/init(string:encodinginvalidcharacters:).md)
- [init(string:relativeTo:)](foundation/nsurl/init(string:relativeto:).md)
- [fileURL(withPath:isDirectory:)](foundation/nsurl/fileurl(withpath:isdirectory:).md)
- [init(fileURLWithPath:isDirectory:)](foundation/nsurl/init(fileurlwithpath:isdirectory:).md)
- [fileURL(withPath:relativeTo:)](foundation/nsurl/fileurl(withpath:relativeto:).md)
- [init(fileURLWithPath:relativeTo:)](foundation/nsurl/init(fileurlwithpath:relativeto:).md)
- [init(fileURLWithPath:isDirectory:relativeTo:)](foundation/nsurl/init(fileurlwithpath:isdirectory:relativeto:).md)
- [fileURL(withPath:)](foundation/nsurl/fileurl(withpath:).md)
- [init(fileURLWithPath:)](foundation/nsurl/init(fileurlwithpath:).md)
- [fileURL(withPathComponents:)](foundation/nsurl/fileurl(withpathcomponents:).md)
- [init(resolvingAliasFileAt:options:)](foundation/nsurl/init(resolvingaliasfileat:options:).md)
- [init(resolvingBookmarkData:options:relativeTo:bookmarkDataIsStale:)](foundation/nsurl/init(resolvingbookmarkdata:options:relativeto:bookmarkdataisstale:).md)
- [fileURL(withFileSystemRepresentation:isDirectory:relativeTo:)](foundation/nsurl/fileurl(withfilesystemrepresentation:isdirectory:relativeto:).md)
- [getFileSystemRepresentation(_:maxLength:)](foundation/nsurl/getfilesystemrepresentation(_:maxlength:).md)
