Pages

Thursday, July 18, 2013

How to join files and compress them into one destination files using zlib in delphi

Do you want to joining some files and compress them into one destination files?. You can do it with your own programming using delphi by copying this code snippet below :

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;
 
That's all the script to join files and compress using zlib library in delphi. If there is something error in code implementation, please contact me by leaving your comment below...

Tuesday, July 16, 2013

How to change boot order in vmware workstation bios

Sometimes, in vmware you want to boot from your flashdisk. You can set it by change the first boot sequence in bios. So, how to boot from bios in vmware workstation?..
Below are the step to do it :
  1. Open vmware workstation
  2. Choose your operating system, for example windows server 2003 Enterprise
  3. Choose VM -> Power -> Power on to BIOS in toolbar as below : 

  4. When vmware bios appeared, choose Boot and change boot order as below : 


That is the step to change boot order to removable disk. If you like it, please don't be shy to leave your comment.
Don't Forget To Join Our Community
×
Widget