加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 目录名称是什么’.’和’..’的意思是faDirectory是什

发布时间:2020-12-15 04:17:18 所属栏目:大数据 来源:网络整理
导读:我有一个程序,用于搜索用户在路径和子路径中输入的文件,除了这一行,我对它的大部分内容都有很好的理解: if ((Rec.Attr and faDirectory) 0) and (Rec.Name'.') and (Rec.Name'..') 整个过程如下,帮助将被欣赏,因为我不确定这行代码的目的,是它检查子路径中
我有一个程序,用于搜索用户在路径和子路径中输入的文件,除了这一行,我对它的大部分内容都有很好的理解:
if ((Rec.Attr and faDirectory) <> 0) and (Rec.Name<>'.') and (Rec.Name<>'..')

整个过程如下,帮助将被欣赏,因为我不确定这行代码的目的,是它检查子路径中的东西?

procedure TfrmProject.btnOpenDocumentClick(Sender: TObject);
begin
FileSearch('C:UsersGuestDocuments',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

解决方法

1) faDirectory attibute指示条目是否是目录.
(Rec.Attr and faDirectory) <> 0 //check if the current TSearchRec element is a directory

2)每个目录有两个Dot Directory Names,在递归扫描中必须避免.

(Rec.Name<>'.') and (Rec.Name<>'..') //check the name of the entry to avoid scan when is `.` or `..`

换句话说,该行表示:仅扫描当前条目是否是目录而不是点目录.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读