怎么用Delphi7实现文件夹的压缩????
解决方案 »
- 在FASTREPRT报表的问题,在报表中有二个明细数据集,分别在放入两个MASTERDATA和FOOT,在每个FOOT中放入对应的MASTDATA的SUM1和SUM2分别求和
- 急,请高手赐教!ADO更新ORACLE数据库的一个问题。
- 一个关闭其他程序的问题!
- 使用Parameters.parambyname时出现的错误
- 请教:这种通讯方式的程序如何实现?
- delphi6安装时没有webservice,如何在安装完毕后安装webservice??
- 帮我看看,关于获取IP地址的问题!
- 请问在delphi中动态生成的控件怎样处理消息?
- 我是新手,请大家帮助
- 我编的程序在 Delphi 的IDE环境下好用,但拷出来时就不好用了,有谁知道是怎么一回事?
- 请问MessageBox的用法!!
- 怎样重新编译组件包?高分
AccessEngine :DBEngine;
begin
AccessEngine:=CoDBEngine.Create;
with dm_zt.Query_ZhTao do
begin
dbpathname:=fieldbyname('db_pathname').asstring;
end;
if FileExists(dbpathname) then
begin
try
try
AccessEngine:=CoDbEngine.Create;
if FileExists(extractfilepath(dbpathname)+'tempback.dat') then deletefile(extractfilepath(dbpathname)+'tempback.dat')
else
begin
AccessEngine.CompactDatabase(dbpathname,extractfilepath(dbpathname)+'tempback.dat','',0,';pwd=B102901010816');
DeleteFile(dbpathname);
renameFile(extractfilepath(dbpathname)+'tempback.dat',dbpathname);
end;
except
ShowMessage('压缩失败');
// raise;
end;
finally
ShowMessage('压缩成功'); end;
可以实现将文件压缩成Zib格式的文件
手动添加文件,设一个S StringList : TStrings;
begin
StringList := TStringList.Create;
try
with StringList do begin
Add(filename+'.dat');
Add(filename+'.in1');
Add(filename+'.in2');
end;
CompressFiles(StringList,filename+'.zip');
label1.Caption:='压缩数据成功';
finally
StringList.free;
end;
end;//如果用对话框,使用多选属性,把files传给files
//Files 要压缩的文件夹(或多个文件),Filename 目标文件,后缀你自己指定
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;//解压缩 Filename原文件 DestDirectory 目标目录
procedure DecompressFiles(const Filename, DestDirectory : String);
var
dest,s : String;
decompr : TDecompressionStream;infile, outfile : TFilestream;
i,l,c : Integer;
begin
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;
vclzip最简单。
with vclzip1 do
begin
zipname:='1111.zip';
fileslist.add('c:\*.*');
zip;
end;