[Lazarus] GetAllFilesMask / AllFilesMask
Bart
bartjunk64 at gmail.com
Mon Apr 22 21:54:28 CEST 2013
On 4/22/13, Juha Manninen <juha.manninen62 at gmail.com> wrote:
> So does *.* on Windows. That is why the TFileSearcher behavior was changed.
But I think it is wrong.
or ((ASearchMask = '*.*') and (ExtractFileExt(PathInfo.Name) = ''))
Now a Filemaks of ???.* will not find 'foo', but it should on Windows.
I think the best strategy is to remove dangling '.*' from ASearchMask
and replace it by '*'
I used something like this in one of my libraries (it works on
maskLists, not a single maks, so it's overcomplex for what we need):
procedure MaskListWinToLinuxWildCards(var AMaskList: String; const
ASeparator: Char);
//All we do here is change any mask that ends in '.*' so that it ends in '*'
//since in Linux if a mask ends in '.*', a '.' must be in the
filename, whilst in Windows
//this translates to may or may not have any extension
var
i: Integer;
S: String;
SL: TStringList;
begin
(*
if (ASeparator = #0) then
begin
exit;
end;
*)
SL := TStringList.Create;
Try
SL.Delimiter := ASeparator;
SL.DelimitedText := AMaskList;
for i := 0 to SL.Count - 1 do
begin
S := SL.Strings[i];
//A Windows mask that ends in a period ('.') is the same as the
mask ending in '.*'
if (S[Length(S)] = '.') then S := S + '*';
//Wildcard end with '.*' ?
if (Length(S) > 1) and (S[Length(S)] = '*') and (S[Length(S)-1]
= '.') then
begin//Replace a wildcard ending in '.*' in one that ends in '*'
if appropriate
if (S = '.*') then S := '*'
else
begin//we know that Length(S) > 2 now...
if (S[Length(S)-2] in ['?','*']) then
begin
System.Delete(S,Length(s),1);
S[Length(S)] := '*';
//Now the mask might end in '**' (if it ended in '*.*' before, so
//if that is the case, we'll remove the last '*'
if (Length(S) > 1) and (S[Length(S)-1] = '*') then
System.Delete(S,Length(S),1);
end
else
begin
//at this point we know that S is something like abc.*
//converting this to abc* is wrong, this would also find
files like abcdef.*
//we want to find in Linux terms both the file abc as well as abc.*
//so we add the entry with the filename without the '.*'
//and leave the current entry as it is
SL.Add(System.Copy(S,1,Length(S)-2));
end;
end;//S <> '.*'
SL.Strings[i]:= S;
end;
end;
AMaskList := SL.DelimitedText;
Finally
SL.Free;
end;
end;
This approach has worked for me on Win and Linux with my backup program.
Bart
More information about the Lazarus
mailing list