Delete Method

Deletes one or more files from an existing archive.

Syntax

public void Delete(string filenames);
Public Sub Delete(ByVal Filenames As String)

Remarks

Delete deletes one or more files from an existing archive, without reprocessing the compressed data. The archive will be opened immediately, and the file(s) will immediately be removed permanently from the archive.

Note that with the Jar component Delete may be used to delete the manifest. Although this is allowed, an exception will be fired after the deletion is complete. The exception may be caught and ignored, or Append may be then used to replace the manifest.

The list of filenames should be specified exactly as when calling Extract:

Filenames may be set to one or more filenames or directory names. Files may be specified with or without a path, and with or without wildcards. If a path is specified, files in the indicated directory will be affected; subdirectories will be recursed into if RecurseSubdirectories is true. If no path is specified but wildcards are, matching files in all directories will be affected. If a single filename without a path is specified, it must correspond exactly to the appropriate value of CompressedName.

Directories should end with a slash ("/"). If a directory is specified, all files and subdirectories in the specified directory will be affected.

A pipe character ("|") should be used to separate multiple file or directory names. Alternatively, the method may be invoked repeatedly.

The ExcludedFiles property may be used to further limit the files to be deleted. When Delete is used to delete a directory or match wildcards, each file to be deleted is first compared against ExcludedFiles, and any files marked as excluded will not be deleted. When Delete is used to delete a single file, the value of ExcludedFiles will be ignored.

When the method is invoked, the Scan method will first be invoked, if it has not been invoked already. Note that if IncludeFiles has been invoked, or if the values of CompressedName and DecompressedName for each file in the Files collection have been set, this information will be reset by the call to Scan.

When deleting multiple files, the component will operate most efficiently if all filenames are passed to Delete in a single invocation of the method. Invoking Delete repeatedly on large archives is not recommended.

Invoking Delete will only remove files from ArchiveFile; it will not delete the files from the disk.

Example


ZipControl.ArchiveFile = "c:\\test.zip"
ZipControl.Delete("default_readme.txt");
ZipControl.Append("\\mydir\\my_readme.txt", "my_readme.txt")

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks ZIP 2020 .NET Edition - Version 20.0 [Build 8300]