那你用
FindResult := FindFirst(Path+'*.*',faAnyFile+faHidden+
faSysFile+faReadOnly,FSearchRec)
然后对搜索结果进行筛选好了。
procedure GetFileList(const AFilePath: string);
var
tmpPath: string;
fpath: String;
srec: TSearchRec;
begin
if Not DirectoryExists(AFilePath) then
Exit;
tmpPath := AFilePath;
if AFilePath[length(AFilePath)] = '/' then
tmpPath := Copy(AFilePath, 1, length(AFilePath)-1);
fpath := tmpPath + '/*.*';
if 0 = FindFirst(fpath, faAnyFile, srec) then
begin
if (srec.Name<>'.')and(srec.Name<>'..') then
begin
if (srec.Attr and faDirectory)=faDirectory then
begin
GetFileList(AFilePath + '/' + srec.Name);
end
else
begin
if (LowerCase(ExtractFileExt(tmpPath + '/' + srec.Name)) = '.wav')
or (LowerCase(ExtractFileExt(tmpPath + '/' + srec.Name)) = '.mp3') then
ListBox1.Items.Add(tmpPath + '/' + srec.Name);
end;
end;
while FindNext(srec)=0 do
begin
if (srec.Name<>'.')and(srec.Name<>'..') then
if (srec.Attr and faDirectory)=faDirectory then
begin
GetFileList(tmpPath + '/' + srec.Name)
end
else
begin
if (LowerCase(ExtractFileExt(tmpPath + '/' + srec.Name)) = '.wav')
or (LowerCase(ExtractFileExt(tmpPath + '/' + srec.Name)) = '.mp3') then
ListBox1.Items.Add(tmpPath + '/' + srec.Name);
end;
end;
end;
FindClose(srec);
end;