我使用此代码将目录中的所有文件合并为一个,而不是真正的压缩,
procedure CompressDirectory(InDir : string; OutStream : TStream);
var
AE : TArchiveEntry;
procedure RecurseDirectory(ADir : string);
var
sr : TSearchRec;
TmpStream : TStream;
begin
if FindFirst(ADir + '*', faAnyFile, sr) = 0 then
begin
repeat
if (sr.Attr and (faDirectory or faVolumeID)) = 0 then
begin
// We have a file (as opposed to a directory or anything
// else). Write the file entry header.
AE.EntryType := aeFile;
AE.FileNameLen := Length(sr.Name);
AE.FileLength := sr.Size;
OutStream.Write(AE, SizeOf(AE));
OutStream.Write(sr.Name[1], Length(sr.Name));
// Write the file itself
TmpStream := TFileStream.Create(ADir + sr.Name, fmOpenRead or fmShareDenyWrite);
OutStream.CopyFrom(TmpStream, TmpStream.Size);
TmpStream.Free;
end;
if (sr.Attr and faDirectory) > 0 then
begin
if (sr.Name <> '.') and (sr.Name <> '..') then
begin
// Write the directory entry
AE.EntryType := aeDirectory;
AE.DirNameLen := Length(sr.Name);
OutStream.Write(AE, SizeOf(AE));
OutStream.Write(sr.Name[1], Length(sr.Name));
// Recurse into this directory
RecurseDirectory(IncludeTrailingPathDelimiter(ADir + sr.Name));
end;
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
// Show that we are done with this directory
AE.EntryType := aeEOD;
OutStream.Write(AE, SizeOf(AE));
end;
begin
RecurseDirectory(IncludeTrailingPathDelimiter(InDir));
end;
如果我希望 compressDirectory 函数不包含某些文件夹和文件怎么办?CompressDirectory 函数代码是什么样的?请指导我,谢谢。
> 为空间编辑、删除图像。