期間從主目錄中的文件和文件夾,我用這個代碼合併所有文件爲一個從一個目錄,而不是真正的壓縮,德爾福功能,不允許壓縮
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函數代碼的外觀如何?請指導我,謝謝。
> 編輯刪除圖像的空間。
請勿將JPG用於非照片圖像。 –
使用ZIP庫 –
請了解如何正確格式化您的代碼,以使其可讀。如果它在發佈之前看起來很糟糕,那就教你自己正確地縮進代碼,即使只是爲了自己。如果你可以閱讀它,現在調試和排除故障要容易得多,並且在未來維護它(尤其是當你與其他人一起工作或公開發布並要求其他人這樣做時)。如果你不能花時間爲我們設計閱讀格式,那麼我們很難有動力花時間去幫助你實現目標。 –