怎么遍文件夹所有文件的MD5

---____--- 2014-11-19 03:57:56

例如:D盘有一个文件夹,里面一个子文件夹,里面都有文件,怎么把所有文件的MD5遍历出来,写到listbox上面,谢谢!
...全文
328 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
aniugee 2014-11-25
  • 打赏
  • 举报
回复
function GetFileList(Path,FileExt:string):TStringList ;
var
sch:TSearchrec;
begin
Result:=TStringlist.Create;
if rightStr(trim(Path), 1) <> '\' then
Path := trim(Path) + '\'
else
Path := trim(Path);
if not DirectoryExists(Path) then
begin
Result.Clear;
exit;
end;
if FindFirst(Path + '*', faAnyfile, sch) = 0 then
begin
repeat
Application.ProcessMessages;
if ((sch.Name = '.') or (sch.Name = '..')) then Continue;
if DirectoryExists(Path+sch.Name) then
begin
Result.AddStrings(GetFileList(Path+sch.Name,FileExt));
end
else
begin
if (UpperCase(extractfileext(Path+sch.Name)) = UpperCase(FileExt)) or (FileExt='.*') then
Result.Add(Path+sch.Name);
end;
until FindNext(sch) <> 0;
SysUtils.FindClose(sch);
end;
end;

procedure TForm3.Button1Click(Sender: TObject);
var
st:TStringList;
I:Integer;
begin
st := GetFileList('E:\123\','.pas');
for I := 0 to st.Count - 1 do
self.ListBox1.AddItem(ExtractFileName(st[I]),nil);
end;


在这个基础上,再加上取文件MD5就行了。取MD5有现成的单元和方法,调用很简单。
levonsoft 2014-11-24
  • 打赏
  • 举报
回复
这个不需要技巧把? 1. 枚举 2. for 计算 md5 整个盘符计算,需要考虑后台慢慢计算,否则卡死..这两个操作都是耗时的.

16,749

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧