<!--
{
  "availability" : [
    "Swift: -"
  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTAttachment/init(compressedContentsOfDirectoryAtURL:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "c:objc(cs)XCTAttachment(cm)attachmentWithCompressedContentsOfDirectoryAtURL:::SYNTHESIZED::c:objc(cs)XCTAttachment"
  },
  "title" : "init(compressedContentsOfDirectoryAtURL:)"
}
-->

# init(compressedContentsOfDirectoryAtURL:)

Creates an attachment containing a zipped archive of an existing directory on disk.

```
convenience init(compressedContentsOfDirectoryAtURL url: URL)
```

## Parameters

`url`

A file URL for a directory whose contents should be compressed.

## Discussion

Zips the contents of the provided directory and wraps the compressed output in an attachment with a [`uniformTypeIdentifier`](/documentation/XCTest/XCTAttachment/uniformTypeIdentifier) of `"public.zip-archive"`. The attachment’s [`name`](/documentation/XCTest/XCTAttachment/name) property is set to the name of the zipped directory followed by an extension of `".zip"`.

Available on macOS only.

---

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)