试了几个包,都不太理想,主要就是只能压缩非中文文件名的文件。最后发现用 unit Zipper 基本可以用,只是压缩后,用360压缩打开这个压缩包,中文文件名都是乱码,但是用自己写的解压缩程序是可以的。
uses
zipper,
......
procedure TForm_Import.bak1Qiye(sOutDir, sOutZipName: string);
var
sFullPathName, sPartPathName, zipfilename: string;
zip: TZipper;
fileList: TStringList;
begin
SetMultiByteConversionCodePage(CP_UTF8);
Cursor := crHourGlass;
zipfilename := sOutDir + '\' + sOutZipName + '.zip';
zip := TZipper.Create;
zip.Filename := zipfilename;
fileList := TStringList.Create;
fileList := FindAllFiles(sPathCurProj, '*.*', true);
for sFullPathName in fileList do
begin
sPartPathName := stringReplace(sFullPathName, ExtractFilePath(ParamStr(0)), '', [rfIgnoreCase]);
zip.Entries.AddFileEntry(sPartPathName);
end;
zip.SaveToFile(zipfilename);
zip.Free;
Cursor := crDefault;
fileList.Free;
end;
解压缩
var
unzipper: TUnzipper;
fnToImport, sArchivePathFn, strXingyongCodeInArchive: string;
begin
if OpenDialog1.Execute then
begin
fnToImport := OpenDialog1.FileName;
unzipper := TUnzipper.Create;
unzipper.Filename := fnToImport;
unzipper.OutputPath := ExtractFilePath(ParamStr(0));
unzipper.Examine;
// 检查data文件夹种是否已经存在重复信用代码
sArchivePathFn := unzipper.Entries[0].ArchiveFileName;
sArchivePathFn := stringReplace(sArchivePathFn, 'data/', '', []);
strXingyongCodeInArchive := copy(sArchivePathFn, 0, pos('/', sArchivePathFn) - 1);
memo1.append('信用代码:' + strXingyongCodeInArchive);
if not DirectoryExists(sPathMain + 'data\' + strXingyongCodeInArchive) then
begin
unzipper.UnzipAllFiles;
memo1.append('导入完成:' + fnToImport);
end
else
begin
memo1.append('已存在该企业。企业信用代码:' + strXingyongCodeInArchive + ' 企业名称: ' + sCurQiyeName);
if MessageDlg('系统提示','已存在该企业。企业信用代码:' + strXingyongCodeInArchive + ' 企业名称: ' + sCurQiyeName + '。需要打开该企业文件夹吗?',mtInformation,[mbOk,mbCancel],0)=mrOk then
begin
OpenDocument(sPathMain + 'data\' + strXingyongCodeInArchive);
end;
end;
unzipper.Free;
end;