<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppleArchive",
  "identifier" : "/documentation/AppleArchive/ArchiveStream/writeDirectoryContents(archiveFrom:path:keySet:selectUsing:flags:threadCount:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Apple Archive",
      "AppleArchive"
    ],
    "preciseIdentifier" : "s:12AppleArchive0B6StreamC22writeDirectoryContents11archiveFrom4path6keySet11selectUsing5flags11threadCounty6System8FilePathV_AMSgAA0B6HeaderC08FieldKeyK0CAP18EntryMessageStatusVAP0wX0V_AmP0W10FilterDataOSgtcSgAA0B5FlagsVSitKF"
  },
  "title" : "writeDirectoryContents(archiveFrom:path:keySet:selectUsing:flags:threadCount:)"
}
-->

# writeDirectoryContents(archiveFrom:path:keySet:selectUsing:flags:threadCount:)

Writes all entries from a directory to the archive stream.

```
func writeDirectoryContents(archiveFrom directory: FilePath, path: FilePath? = nil, keySet: ArchiveHeader.FieldKeySet, selectUsing filter: ArchiveHeader.EntryFilter? = nil, flags: ArchiveFlags = [], threadCount: Int = 0) throws
```

## Parameters

`directory`

The base directory that the operation scans and archives.

`path`

An optional subdirectory to restrict the scan.

`keySet`

The fields to include for each entry.

`filter`

A closure that’s called for each entry that’s received by the stream.

`flags`

Flags that control the behavior of the operation.

`threadCount`

The number of worker threads that the operation uses, set to `0` for default.

---

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)