zwz_good  

  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

Description

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:

Constant 
Description 
Read-only files  
Hidden files  
System files  
Volume ID files  
Directory files  
Archive files  
Any file  

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.

Note: FindFirst allocates resources (memory) which must be released by calling FindClose.
Note: Some of the file attribute constants are not valid on all platforms. For example, faVolumeID and faArchive will not work on Linux.

 

Pascal

function FindNext(var F: TSearchRec): Integer;
Returns the next entry matching the name and attributes specified in a previous call to FindFirst.

File

SysUtils

Description

FindNext returns the next entry that matches the name and attributes specified in a previous call to FindFirst. The search record must be one that was passed to FindFirst. The return value is zero if the function was successful. Otherwise the return value is an error code.  

posted on 2009-04-13 15:49  zwz_good  阅读(192)  评论(0编辑  收藏  举报