procedure SearchFile(path:string); //注意:path实参 字符串后要加 ' \ '
var
SearchRec:TSearchRec;
found:integer;
begin
found:=FindFirst(Path+'*.*',faAnyFile,SearchRec);
while found=0 do
begin
if (SearchRec.Name<>'.') and (SearchRec.name<>'..') and
(SearchRec.Attr=faDirectory) then
SearchFile(Path+SearchRec.Name+'\')
else
Form1.mmo1.Lines.Add(SearchRec.Name);
found:=FindNext(SearchREc);
end;
FindClose(SearchRec);
end;
相关函数
function FindFirst(const Path: string; Attr: Integer; var F: TSearchRec): Integer;
Searches for the first instance of a file name with a given set of attributes in a specified directory.
File
SysUtils
FindFirst searches the directory specified by Path for the first file that matches the file name implied by Path and the attributes specified by the Attr parameter. The result is returned in the F parameter. Use the fields of this search record to extract the information needed. FindFirst returns 0 if a file was successfully located, otherwise, it returns an error code.
The Path constant parameter is the directory and file name mask, including wildcard characters. For example, '.\test\*.*' specifies all files in the test subdirectory.
The Attr parameter specifies the special files to include in addition to all normal files. Choose from these file attribute constants when specifying the Attr parameter:
Attributes can be combined by adding (Delphi) or or-ing (C++) their constants or values. For example, to search for read-only and hidden files in addition to normal files, pass (faReadOnly + faHidden) in Delphi or (faReadOnly | faHidden) in C++ as the Attr parameter. To include only normal files, pass zero for the Attr parameter.
Pascal
function FindNext(var F: TSearchRec): Integer;
Returns the next entry matching the name and attributes specified in a previous call to FindFirst.
SysUtils