Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Потрепаться";
Текущий архив: 2005.09.25;
Скачать: [xml.tar.bz2];

Вниз

Доработать >>>Соединить и сжать несколько файлов в один.<<<   Найти похожие ветки 

 
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;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.47 MB
Время: 0.039 c
5-1100515449
Lisii
2004-11-15 13:44
2005.09.25
Компонент наследник TGraphicsControl - вращение объёмной фигуры


1-1125398415
kyn66
2005-08-30 14:40
2005.09.25
Поиск в ListBox не работает из-за цифр?


1-1125822158
RayGun
2005-09-04 12:22
2005.09.25
QuickReport или экспорт в Excel


14-1125298599
ПЛОВ
2005-08-29 10:56
2005.09.25
Подскажите, как проверить PHP-скрипты на локальном компьютере?


3-1123592233
Shopot
2005-08-09 16:57
2005.09.25
ADO и база данных Access.





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский