问两个问题压缩目录/得到目录下所有文件列表?(200分)

  • 主题发起人 主题发起人 chinaluo
  • 开始时间 开始时间
C

chinaluo

Unregistered / Unconfirmed
GUEST, unregistred user!
我正在做一个项目,由于时间关系,不想写这两个部分了,想请大家帮忙看看大家有没有这两个处理的源代码.
压缩目录下的所有文件和子目录,并能解压到指定的目录下.

得到指定目录下所有的文件,包括子目录下的文件.

都谢了.......
 
procedure FindFiles(const AFileType, APath: string; AFileList: TStrings);
var
strType,
strPath: string;
cSearchRec: TSearchRec;
begin
Assert(AFileList <> nil);

strPath := IncludeTrailingPathDelimiter(APath);
if AFileType = '' then
strType := '*.*'
else strType := AFileType;
if FindFirst(strPath + strType, faAnyFile and (not faDirectory), cSearchRec) = 0 then
repeat
if cSearchRec.Name <> '' then
AFileList.Add(strPath + cSearchRec.Name);
until FindNext(cSearchRec) <> 0;
SysUtils.FindClose(cSearchRec);
if FindFirst(strPath + '*.*', faDirectory, cSearchRec) = 0 then;
repeat
if (cSearchRec.Name <> '') and not IsDirNotation(cSearchRec.Name) then
FindFiles(strType, strPath + cSearchRec.Name, AFileList);
until FindNext(cSearchRec) <> 0;
SysUtils.FindClose(cSearchRec);
end;
 
好,等待中...
 
还有一个问题了?有人答吗?
 
还要等啊.
 
用 ZIPTV 控件包轻松搞定。。。
用到其中的 TZip 和 TUnZip 控件
函数:
function DeCompressFile(sourceFile, targetPath: string): Boolean;
var
FilesExtracted: Integer;
begin
result := False;
UnZIP1.ArchiveFile := sourceFile; // archive filename
// UnZIP1.Passwords.Add('123');
UnZIP1.ConfirmOverwrites := false; // default = False
UnZIP1.RecurseDirs := true; // default = False
UnZIP1.FileSpec.Clear(); //
UnZIP1.FileSpec.Add('*.*'); // *.* = extract all
UnZIP1.ExtractDir := targetPath; //
FilesExtracted := UnZIP1.Extract();
if FilesExtracted = 0 then
result := false
else
result := true;
end;

function CompressFile(sourcePath, targetFName: string): Boolean;
var
FilesCompressed: Integer;
begin
result := False;
if FileExists(targetFName) then
EraseFile(targetFName, doAllowUndo); // EraseFile is in ztvBase.pas
Zip1.ArchiveFile := targetFName; // archive filename
Zip1.DateAttribute := daFileDate; // default value
Zip1.StoredDirNames := sdRelative; // default value
Zip1.CompressMethod := cmDeflate; // default value
Zip1.RecurseDirs := true; // default = False
Zip1.Switch := swAdd; // default value
Zip1.StoreEmptySubDirs := False; // default value
Zip1.EncryptHeaders := false; // default = False
Zip1.ExcludeSpec.Clear();
Zip1.FileSpec.Clear();
Zip1.FileSpec.Add(sourcePath + '*.*');
// test with c:/windows/*.txt
// ****************************************************************
// NOTE: for a better understanding of how the Attributes property
// works with file attributes see demo demos/filescan/fs_demo.dpr.
// ****************************************************************
// See the Attributes property in the object inspector
// Set Zip1 Attributes property by calling the SetAttribute method
Zip1.SetAttribute(fsZeroAttr, True); // default
Zip1.SetAttribute(fsArchive, True); // default
Zip1.SetAttribute(fsDirectory, True); // default = False
Zip1.SetAttribute(fsHidden, True); // default = False
Zip1.SetAttribute(fsReadOnly, True); // default
Zip1.SetAttribute(fsSysFile, True); // default = False
// See the AttributesEx property in teh object inspector
// Set the AttributesEx property by calling the SetAttributeEx method.
// Exclude none
Zip1.SetAttributeEx(fsZeroAttr, False); // default
Zip1.SetAttributeEx(fsArchive, False); // default
Zip1.SetAttributeEx(fsDirectory, False); // default
Zip1.SetAttributeEx(fsHidden, False); // default
Zip1.SetAttributeEx(fsReadOnly, False); // default
Zip1.SetAttributeEx(fsSysFile, False); // default
// UnZIP1.Password:='huaruan';
FilesCompressed := Zip1.Compress();
// ShowMessage( 'Files Compressed: ' + IntToStr( FilesCompressed ) );
result := true;
end;
调用例子:
if not CompressFile( 'c:/temp/', 'c:/test.zip') then
begin
showmessage('压缩文件失败,请检查路径正确性!');
exit;
end;
//-------------------------------------
if not deCompressFile('c:/test.zip', 'c:/temp/') then
begin
showmessage('解压压缩文件失败,请检查是否为该系统的压缩文件!');
exit;
end;
 
后退
顶部