ADD: Find files - exclude directories with absolute path

This commit is contained in:
Alexander Koblov 2023-02-18 12:45:52 +03:00
commit cb15de0993
3 changed files with 18 additions and 11 deletions

View file

@ -272,7 +272,7 @@ begin
if AFile.IsDirectory or AFile.IsLinkToDirectory then
begin
Matches := CheckDirectoryName(FFileChecks, aFile.Name) and
CheckDirectoryNameRelative(FFileChecks, aFile.FullPath, FRootDir);
CheckDirectoryNameEx(FFileChecks, aFile.FullPath, FRootDir);
end
else begin
Matches := CheckFile(FFileTemplate.SearchRecord, FFileChecks, aFile);

View file

@ -126,7 +126,7 @@ type
function CheckPlugin(const SearchTemplate: TSearchTemplateRec; const FileName: String) : Boolean;
function CheckDirectoryName(const FileChecks: TFindFileChecks; const DirectoryName: String) : Boolean;
function CheckDirectoryNameRelative(const FileChecks: TFindFileChecks; const FullPath, BasePath: String) : Boolean;
function CheckDirectoryNameEx(const FileChecks: TFindFileChecks; const FullPath, BasePath: String) : Boolean;
function CheckFileName(const FileChecks: TFindFileChecks; const FileName: String) : Boolean;
function CheckFileTime(const FileChecks: TFindFileChecks; FT : TFileTime) : Boolean; inline;
function CheckFileDateTime(const FileChecks: TFindFileChecks; DT : TDateTime) : Boolean;
@ -426,7 +426,7 @@ begin
end;
end;
function CheckDirectoryNameRelative(const FileChecks: TFindFileChecks; const FullPath, BasePath: String): Boolean;
function CheckDirectoryNameEx(const FileChecks: TFindFileChecks; const FullPath, BasePath: String): Boolean;
var
APath: String;
begin
@ -435,11 +435,18 @@ begin
begin
for APath in ExcludeDirectories.Split([';'], TStringSplitOptions.ExcludeEmpty) do
begin
// Check if FullPath is a path relative to BasePath.
if GetPathType(APath) = ptRelative then
begin
if MatchesMask(ExtractDirLevel(BasePath, FullPath), APath) then
Exit(False);
case GetPathType(APath) of
ptRelative:
begin
// Check if FullPath is a path relative to BasePath.
if MatchesMask(ExtractDirLevel(BasePath, FullPath), APath) then
Exit(False);
end;
ptAbsolute:
begin
if MatchesMask(FullPath, APath) then
Exit(False);
end;
end;
end;
end;

View file

@ -320,9 +320,9 @@ begin
with FSearchTemplate do
begin
Result := CheckDirectoryName(FolderName) and
CheckDirectoryNameRelative(FFileChecks,
CurrentDir + PathDelim + FolderName,
FSearchTemplate.StartPath);
CheckDirectoryNameEx(FFileChecks,
CurrentDir + PathDelim + FolderName,
FSearchTemplate.StartPath);
end;
end;