这么获得一个目录下有几个后缀为“.txt”的文件?(100分)

  • 主题发起人 主题发起人 qinsir
  • 开始时间 开始时间
Q

qinsir

Unregistered / Unconfirmed
GUEST, unregistred user!
我想获得这些文件的名称和数量,我该咋整呢?
谢谢




——————————————————
你好就是我好,我好也就是你好,所以谁好都一样
 
function TfrmMain.GetPathFile(S:String;Attr:Integer):TStringList;
var
sr:TSearchRec;
fReturn:Integer;
FileList:TStringList;
begin
FileList:=TStringList.Create;
fReturn:=FindFirst(S,Attr,sr);
if fReturn=0 then
begin
repeat
begin
if (Attr=faAnyFile) and (length(sr.Name)<=11) then
FileList.Add(sr.Name)
else if (Attr=faDirectory) and (length(sr.Name)>2) then
begin
try
FileList.Add(ConvertToSort(sr.Name));
except
end;
end;
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
Result:=FileList;
end;
调用方法:
GetPathFile('C:/windows/*.txt';faAnyFile):返回的TStringList就包含了所有的txt文件。
这是我的一个函数,有些对你来说没用的东西,可以删掉。
 
var
sum:integer;
searchRec:TsearchRec;
begin
sum := 0;
if (FindFirst(yourpath+'*.TXT', faAnyFile, SearchRec)=0) then
begin
Repeat
memo1.lines.add(SearchRec.name); //filename
sum := sum + 1 ;
until FindNext(SearchRec) <> 0
end;
FindClose(SearchRec);
 
多人接受答案了。
 
后退
顶部