Delphi 目录名';是什么';和'';faDirectory是什么意思?

Delphi 目录名';是什么';和'';faDirectory是什么意思?,delphi,delphi-7,Delphi,Delphi 7,我有一个搜索用户在路径和子路径中输入的文件的过程,我对其中的大部分都有很好的理解,除了这一行: if ((Rec.Attr and faDirectory) <> 0) and (Rec.Name<>'.') and (Rec.Name<>'..') if((Rec.Attr和faDirectory)0)和(Rec.Name'.'和(Rec.Name'.) 整个过程如下所示,希望您能提供帮助,因为我不确定这行代码的确切用途,是否正在检查子路径中的某些内容

我有一个搜索用户在路径和子路径中输入的文件的过程,我对其中的大部分都有很好的理解,除了这一行:

if ((Rec.Attr and faDirectory) <> 0) and (Rec.Name<>'.') and (Rec.Name<>'..')
if((Rec.Attr和faDirectory)0)和(Rec.Name'.'和(Rec.Name'.)
整个过程如下所示,希望您能提供帮助,因为我不确定这行代码的确切用途,是否正在检查子路径中的某些内容

procedure TfrmProject.btnOpenDocumentClick(Sender: TObject);
begin
FileSearch('C:\Users\Guest\Documents', edtDocument.Text+'.docx');
end;

procedure TfrmProject.FileSearch(const Pathname, FileName : string);
var Word : Variant;
    Rec  : TSearchRec;
    Path : string;
begin
Path := IncludeTrailingBackslash(Pathname);
if FindFirst(Path + FileName, faAnyFile - faDirectory, Rec) = 0
then repeat Word:=CreateOLEObject('Word.Application');
  Word.Visible:=True;
  Word.Documents.Open(Path + FileName);
   until FindNext(Rec) <> 0;
FindClose(Rec);


if FindFirst(Path + '*.*', faDirectory, Rec) = 0 then
 try
   repeat
   if ((Rec.Attr and faDirectory) <> 0)  and (Rec.Name<>'.') and (Rec.Name<>'..') then
     FileSearch(Path + Rec.Name, FileName);
  until FindNext(Rec) <> 0;
 finally
 FindClose(Rec);
end;

end; //procedure FileSearch
过程TfrmProject.btnopendiumentclick(发送方:TObject);
开始
文件搜索('C:\Users\Guest\Documents',edtDocument.Text+'.docx');
结束;
过程TfrmProject.FileSearch(const路径名,文件名:string);
变量词:变体;
Rec:TSearchRec;
路径:字符串;
开始
路径:=includeTrailingBackslax(路径名);
如果FindFirst(路径+文件名,faAnyFile-faDirectory,Rec)=0
然后重复单词:=CreateOLEObject('Word.Application');
可见:=真;
Word.Documents.Open(路径+文件名);
直到FindNext(Rec)0;
FindClose(Rec);
如果FindFirst(路径+'*.*',faDirectory,Rec)=0,则
尝试
重复
如果((Rec.Attr和faDirectory)0)和(Rec.Name'.'和(Rec.Name'.'),则
文件搜索(路径+记录名、文件名);
直到FindNext(Rec)0;
最后
FindClose(Rec);
结束;
结束//程序文件搜索
1)attibute指示条目是否为目录

 (Rec.Attr and faDirectory) <> 0 //check if the current TSearchRec element is a directory
(Rec.Attr和faDirectory)0//检查当前TSearchRec元素是否为目录
2) 每个目录有两个,在递归扫描中必须避免

(Rec.Name<>'.') and (Rec.Name<>'..') //check the name of the entry to avoid scan when is `.` or `..`
(Rec.Name'.'和(Rec.Name'..)//检查条目的名称,以避免在`.`或`.`时进行扫描`

换句话说,该行的意思是:仅当当前条目是目录而不是
点目录时才进行扫描,因此(Rec.Attr和faDirectory)在当前TSearchRec元素是目录时返回负值?为什么会这样?否,行
(Rec.Attr和faDirectory)
使用
操作数检查
faDirectory
($00000010)值是否设置在条目的属性中。我明白了,非常感谢。我知道这不是最初的问题,从技术上讲,我应该创建一个新问题,但我想知道您是否有时间向我建议如何使用showmessage来指示未找到I文件,我尝试将一个布尔变量放入变量filefind设置为false的位置,但是FileFound:=如果FindFirst(Path+FileName,faAnyFile-faDirectory,Rec)=0,则为true,但是作为一个递归过程,这不起作用,有什么简单的方法可以实现它吗?您可以让
FileSearch()
返回一个
布尔值
,指示它是否在任何给定的迭代中找到文件。一旦迭代返回
True
,继续向上传递
True
接收链到原始调用方。仅供参考,在XP和更高版本上,有一个可用的
SearchPath()
函数,可以在指定路径中搜索文件名,这样您就不必再手动搜索了。我已经完成了这项工作,它可以正常工作,但当显示消息时,我按ok键,它会不断重新出现,即使我在过程结束时收到了它