0
then a file to be added is first compressed to a temporary archive which is created
in:
CZipArchive zip; zip.Open(_T("C:\\Temp\\test.zip")); CZipAddNewFileInfo info(_T("C:\\Temp\\file.dat"), _T("replacement.dat")); // replace the first file in the archive info.m_uReplaceIndex = 0; zip.AddNewFile(info); zip.Close();
If you don't want to physically remove the file from the archive, but only from
the central directory (e.g. to save the processing time or for safer archive modifications),
use the CZipArchive::RemoveFile method and set the
bRemoveData
parameter to false
.
CZipArchive zip; zip.Open(_T("C:\\Temp\\test.zip")); // delete the first file zip.RemoveFile(0); // delete two first files CZipIndexesArray indexes; indexes.Add(0); indexes.Add(1); zip.RemoveFiles(indexes); // delete files by their names CZipStringArray names; names.Add(_T("Temp\\file1.dat")); names.Add(_T("file4.dat")); zip.RemoveFiles(names); zip.Close();
CZipArchive zip; zip.Open(_T("C:\\Temp\\test.zip")); zip.SetCommitMode(CZipArchive::cmManual); // rename the first file in the archive zip[0]->SetFileName(_T("renamed.dat")); zip[2]->SetFileName(_T("renamed2.dat")); zip.CommitChanges(); // perform possibly some other operations zip.Close();
CZipArchive zip; zip.Open(_T("C:\\Temp\\test.zip")); zip.SetCommitMode(CZipArchive::cmManual); // rename the first file in the archive zip[0]->SetFileName(_T("renamed.dat")); zip[2]->SetFileName(_T("renamed2.dat")); // this will call CommitChanges zip.Close();
CZipArchive zip; zip.Open(_T("C:\\Temp\\test.zip")); int iIndexOfFile = 1; // read the local header information zip.ReadLocalHeader(iIndexOfFile); CZipFileHeader* pHeader = zip.GetFileInfo(iIndexOfFile); // set the time pHeader->SetTime(time(0)); // write the local header information zip.OverwriteLocalHeader(iIndexOfFile); zip.RemoveCentralDirectoryFromArchive(); // the central directory will be written back to the archive // during closing zip.Close();