16,748
社区成员
发帖
与我相关
我的任务
分享
function TForm1.GetALLFileOfCount(fDirName: string): Integer;
var
hFindFile:Cardinal;
TFile,ListName:string;
SCurDir:string[255];
FindFileData: WIN32_FIND_DATA;
begin
SCurDir:=GetCurrentDir;
ChDir(fDirname);
hFindFile:=FindFirstFile('*.*',FindFileData);
if fDirName[Length(fDirName)] <> '\' then
fDirName:=fDirName + '\';
if hFindFile <> INVALID_HANDLE_VALUE then
begin
repeat
begin
TFile:= FindFileData.cFileName;
if (TFile = '.') or (TFile = '..') then
Continue;
if FindFileData.dwFileAttributes=FILE_ATTRIBUTE_DIRECTORY then
begin
if fDirName[Length(fDirName)] <> '\' then
GetALLFileOfCount(fDirName+'\'+TFile)
else
GetALLFileOfCount(fDirName+TFile);
end
else
fCount:= fCount+1;
ListName := fDirName + TFile;
lst1.Items.Add(ListName + IntToStr(fCount));
end;
until FindNextFile(hFindFile,FindFileData) = False;
end
else
begin
ChDir(sCurDir);
CloseHandle(hFindFile);
exit;
end;
Result := fCount;
end;
procedure TForm1.btn1Click(Sender: TObject);
var
i : Integer;
begin
i:=GetALLFileOfCount(edt1.Text);
ShowMessage(IntToStr(i));
end;
function TForm1.GetALLFileOfCount(fDirName: string): Integer;
var
hFindFile:Cardinal;
TFile,ListName,Path:string;
SCurDir:string[255];
FindFileData: WIN32_FIND_DATA;
begin
SCurDir:=GetCurrentDir;
ChDir(fDirname);
hFindFile:=FindFirstFile('*.*',FindFileData);
if fDirName[Length(fDirName)] <> '\' then
fDirName:=fDirName + '\';
if hFindFile <> INVALID_HANDLE_VALUE then
begin
repeat
TFile:= FindFileData.cFileName;
if (TFile = '.') or (TFile = '..')
then Continue;
if FindFileData.dwFileAttributes=FILE_ATTRIBUTE_DIRECTORY then
begin
if fDirName[Length(fDirName)] <> '\'
then Path:=fDirName+'\'+TFile
else Path:=fDirName+TFile;
GetALLFileOfCount(Path)
end
else fCount:= fCount+1;
if FindFileData.dwFileAttributes<>FILE_ATTRIBUTE_DIRECTORY then
begin
ListName := fDirName + TFile;
ListBox1.Items.Add(ListName +' '+IntToStr(fCount));
end;
until FindNextFile(hFindFile,FindFileData) = False;
end
else begin
ChDir(sCurDir);
CloseHandle(hFindFile);
exit;
end;
Result := fCount;
end;