Текущий архив: 2005.09.25;
Скачать: CL | DM;
Вниз
Доработать >>>Соединить и сжать несколько файлов в один.<<< Найти похожие ветки
← →
Windows © (2005-08-27 13:13) [0]>>>Соединить и сжать несколько файлов в один.<<<
Вот листинг :
uses Zlib;
procedure CompressFiles(Files : TStrings; const Filename : String);
var
infile, outfile, tmpFile : TFileStream;
compr : TCompressionStream;
i,l : Integer;
s : String;
begin
if Files.Count > 0 then
begin
outFile := TFileStream.Create(Filename,fmCreate);
try
{ the number of files }
l := Files.Count;
outfile.Write(l,SizeOf(l));
for i := 0 to Files.Count-1 do
begin
infile := TFileStream.Create(Files[i],fmOpenRead);
try
{ the original filename }
s := ExtractFilename(Files[i]);
l := Length(s);
outfile.Write(l,SizeOf(l));
outfile.Write(s[1],l);
{ the original filesize }
l := infile.Size;
outfile.Write(l,SizeOf(l));
{ compress and store the file temporary}
tmpFile := TFileStream.Create("tmp",fmCreate);
compr := TCompressionStream.Create(clMax,tmpfile);
try
compr.CopyFrom(infile,l);
finally
compr.Free;
tmpFile.Free;
end;
{ append the compressed file to the destination file }
tmpFile := TFileStream.Create("tmp",fmOpenRead);
try
outfile.CopyFrom(tmpFile,0);
finally
tmpFile.Free;
end;
finally
infile.Free;
end;
end;
finally
outfile.Free;
end;
DeleteFile("tmp");
end;
end;
procedure DecompressFiles(const Filename, DestDirectory : String);
var
dest,s : String;
decompr : TDecompressionStream;
infile, outfile : TFilestream;
i,l,c : Integer;
begin
// IncludeTrailingPathDelimiter (D6/D7 only)
dest := IncludeTrailingPathDelimiter(DestDirectory);
infile := TFileStream.Create(Filename,fmOpenRead);
try
{ number of files }
infile.Read(c,SizeOf(c));
for i := 1 to c do
begin
{ read filename }
infile.Read(l,SizeOf(l));
SetLength(s,l);
infile.Read(s[1],l);
{ read filesize }
infile.Read(l,SizeOf(l));
{ decompress the files and store it }
s := dest+s; //include the path
outfile := TFileStream.Create(s,fmCreate);
decompr := TDecompressionStream.Create(infile);
try
outfile.CopyFrom(decompr,l);
finally
outfile.Free;
decompr.Free;
end;
end;
finally
infile.Free;
end;
end;
Procedure Compress;
Begin
Memo1.Lines.Add("C:\1.exe");
Memo1.Lines.Add("C:\2.exe");
CompressFiles(Memo1.Lines,"C:\result.exe");
End;
Procedure DeCompress;
Begin
DecompressFiles("C:\result.exe", "C:\");
End;
Поясню, как работает программа, у меня...
Procedure Compress;
Склеивает и файлы C:\1.exe & C:\2.exe в один и сжимает.
Получается файл C:\Result.exe;
Procedure DeCompress;
Разъединяет файл C:\Result.exe
И сохраняте в дирректорию файлы, которые сжала предыдущая процедура.
Соответсвенно в дирректрии C:\ получаются прежние два файла.
Теперь, что касается вопроса.
Обе процедуры прекрасно работают.
Но как доработать код процедуры
procedure CompressFiles(Files : TStrings; const Filename : String);
Так, чтобы результативный файл(C:\Result.exe) запускался, не просто досовским окошком, которое тут же исчезает, а запускал те два
файл. Сначала первый, потом второй.
← →
XProger © (2005-08-27 13:25) [1]а Result.exe твой винда хоть понимает чтобы запускать? ;)
← →
Anatoly Podgoretsky © (2005-08-27 15:38) [2]Windows © (27.08.05 13:13)
Самозванец Windows это умеет делать.
← →
Windows © (2005-08-27 16:06) [3]"а Result.exe твой винда хоть понимает чтобы запускать? ;)"
Дак вот, я и пытаюсь у вас выяснить, как сделать так, чтобы она "Понимала..."
← →
Anatoly Podgoretsky © (2005-08-27 16:20) [4]Windows это делает по правой кнопке мыши.
← →
Windows © (2005-08-27 18:19) [5]Удалено модератором
← →
Windows © (2005-08-28 09:18) [6]Да, нормально...
Дак, люди, никто не может помочь???
← →
Sam Stone © (2005-08-28 15:10) [7]Не дай бог этот код будет работать так, как хочет автор ;)
Причем ведь есть такая возможность, если не ошибаюсь (*.rc)
← →
pasha_golub © (2005-08-28 19:19) [8]Windows © (28.08.05 09:18) [6]
Обычно животных с большими проблемами усыпляют... Чем же помочь Вам я не знаю.
Страницы: 1 вся ветка
Текущий архив: 2005.09.25;
Скачать: CL | DM;
Память: 0.47 MB
Время: 0.045 c