FileManager

extension FileManager
  • Zips the file or direcory contents at the specified source URL to the destination URL.

    If the item at the source URL is a directory, the directory itself will be represented within the ZIP Archive. Calling this method with a directory URL file:///path/directory/ will create an archive with a directory/ entry at the root level. You can override this behavior by passing false for shouldKeepParent. In that case, the contents of the source directory will be placed at the root of the archive.

    Throws

    Throws an error if the source item does not exist or the destination URL is not writable.

    Declaration

    Swift

    public func zipItem(at sourceURL: URL, to destinationURL: URL,
                        shouldKeepParent: Bool = true, compressionMethod: CompressionMethod = .none,
                        progress: Progress? = nil) throws

    Parameters

    sourceURL

    The file URL pointing to an existing file or directory.

    destinationURL

    The file URL that identifies the destination of the zip operation.

    shouldKeepParent

    Indicates that the directory name of a source item should be used as root element within the archive. Default is true.

    compressionMethod

    Indicates the CompressionMethod that should be applied.

    progress

    A progress object that can be used to track or cancel the zip operation.