例如:D盤有一個檔案夾,里面一個子檔案夾,里面都有檔案,怎么把所有檔案的MD5遍歷出來,寫到listbox上面,謝謝!
uj5u.com熱心網友回復:
這個不需要技巧把?1. 列舉
2. for 計算 md5
整個盤符計算,需要考慮后臺慢慢計算,否則卡死..這兩個操作都是耗時的.
uj5u.com熱心網友回復:
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有現成的單元和方法,呼叫很簡單。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/95953.html
標籤:語言基礎/算法/系統設計
