---
title: "init(directoryWithFileWrappers:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/filewrapper/init(directorywithfilewrappers:)"
---

# init(directoryWithFileWrappers:)

Initializes the receiver as a directory file wrapper, with a given file-wrapper list.

## Declaration

```swift
init(directoryWithFileWrappers childrenByPreferredName: [String : FileWrapper])
```

## Parameters

- `childrenByPreferredName`: Key-value dictionary of file wrappers with which to initialize the receiver. The dictionary must contain entries whose values are the file wrappers that are to become children and whose keys are filenames. See https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileWrappers/FileWrappers.html#//apple_ref/doc/uid/TP40010672-CH13-SW1 in https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40010672 for more information about the file-wrapper list structure.

## Return Value

Return Value Initialized file wrapper for fileWrappers.

## Discussion

Discussion After initialization, the file wrapper is not associated with a file-system node until you save it using write(to:options:originalContentsURL:). The receiver is initialized with open permissions: anyone can read, write, or modify the directory on disk. If any file wrapper in the directory doesn’t have a preferred filename, its preferred name is automatically set to its corresponding key in the childrenByPreferredName dictionary.

## See Also

### Related Documentation

- [preferredFilename](foundation/filewrapper/preferredfilename.md)
- [filename](foundation/filewrapper/filename.md)
- [fileAttributes](foundation/filewrapper/fileattributes.md)

### Creating File Wrappers

- [init(url:options:)](foundation/filewrapper/init(url:options:)-70161.md)
- [init(path:)](foundation/filewrapper/init(path:).md)
- [init(regularFileWithContents:)](foundation/filewrapper/init(regularfilewithcontents:).md)
- [init(symbolicLinkWithDestination:)](foundation/filewrapper/init(symboliclinkwithdestination:).md)
- [init(symbolicLinkWithDestinationURL:)](foundation/filewrapper/init(symboliclinkwithdestinationurl:).md)
- [init(serializedRepresentation:)](foundation/filewrapper/init(serializedrepresentation:).md)
