<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.6.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/FileWrapper/init(url:options:)-70161",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileWrapper(im)initWithURL:options:error:"
  },
  "title" : "init(url:options:)"
}
-->

# init(url:options:)

Initializes a file wrapper instance whose kind is determined by the type of file-system node located by the URL.

```
init(url: URL, options: FileWrapper.ReadingOptions = []) throws
```

## Parameters

`url`

URL of the file-system node the file wrapper is to represent.

`options`

Option flags for reading the node located at `url`. See [`FileWrapper.ReadingOptions`](/documentation/Foundation/FileWrapper/ReadingOptions) for possible values.

## Return Value

File wrapper for the file-system node at `url`. May be a directory, file, or symbolic link, depending on what is located at the URL. Returns <doc://com.apple.documentation/documentation/Swift/false> (0) if reading is not successful.

## Discussion

If `url` is a directory, this method recursively creates file wrappers for each node within that directory. Use the [`fileWrappers`](/documentation/Foundation/FileWrapper/fileWrappers) property to get the file wrappers of the nodes contained by the directory.

> Handling Errors in Swift:
> In Swift, this API is imported as an initializer and is marked with the `throws` keyword to indicate that it throws an error in cases of failure.
> 
> You call this method in a `try` expression and handle any errors in the `catch` clauses of a `do` statement, as described in [Error Handling](https://docs.swift.org/swift-book/LanguageGuide/ErrorHandling.html) in [The Swift Programming Language](https://docs.swift.org/swift-book/) and `About Imported Cocoa Error Parameters`.

## See Also

[`fileWrappers`](/documentation/Foundation/FileWrapper/fileWrappers)

The file wrappers contained by a directory file wrapper.

[`preferredFilename`](/documentation/Foundation/FileWrapper/preferredFilename)

The preferred filename for the file wrapper object.

[`-  readFromURL:options:error:`](/documentation/Foundation/FileWrapper/read(from:options:))

Recursively rereads the entire contents of a file wrapper from the specified location on disk.

[`filename`](/documentation/Foundation/FileWrapper/filename)

The filename of the file wrapper object

  [File System Programming Guide](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40010672)

[`fileAttributes`](/documentation/Foundation/FileWrapper/fileAttributes)

A dictionary of file attributes.



---

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)