What are directory names ?. and ".." means and what does the directory mean?

I have a procedure that looks for the file entered by the user in the path and subpath, I am well versed for the most part except this line:

if ((Rec.Attr and faDirectory) <> 0) and (Rec.Name<>'.') and (Rec.Name<>'..')

The whole procedure is this: help will be appreciated, since im not sure exactly what the purpose of this line of code is, does anything check in the subpath ?.

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
+5
source share
1 answer

1) The faDirectory element indicates whether the entry is a directory.

 (Rec.Attr and faDirectory) <> 0 //check if the current TSearchRec element is a directory

2) Each directory has two Dot Directory Names that should be avoided during recursive scanning.

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

, : , Dot Directory.

+10

All Articles