i serach filename=*.doc
content = '123'
find some files which doesn't contain '123'.
also
i search some asian language strings(eg:Chinese simp),cannot find any result.
i use Delphi 2007 + tnt unicode v2.0.3, and your unidcode version TFindFile.
function FileContainsPhrase(const FileName: WideString;
const Phrase: TStringVariants; Options: TContentSearchOptions): Boolean;
const
UNICODE_BOM: WideChar = #$FEFF;
UNICODE_BOM_SWAPPED: WideChar = #$FFFE;
UTF8_BOM: array[1..3] of AnsiChar = (#$EF, #$BB, #$BF);
var
Stream: TFileStream;
BOMBytes: array[1..3] of AnsiChar;
BOM: WideChar absolute BOMBytes;
BOMSize: Integer;
begin
Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
try
BOMSize := Stream.Read(BOM, SizeOf(BOM));
if BOMSize = SizeOf(BOM) then
begin
if (BOM = UNICODE_BOM) or (BOM = UNICODE_BOM_SWAPPED) then
begin
Result := StreamContainsPhraseWide(Stream, PWideChar(Phrase.Unicode),
Length(Phrase.Unicode), Options, BOM = UNICODE_BOM_SWAPPED);
Exit;
end
else if (BOMBytes[1] = UTF8_BOM[1]) and (BOMBytes[2] = UTF8_BOM[2]) then
begin
Inc(BOMSize, Stream.Read(BOMBytes[3], SizeOf(BOMBytes[3])));
if (BOMSize = SizeOf(UTF8_BOM)) and (BOMBytes[3] = UTF8_BOM[3]) then
begin
Result := StreamContainsPhraseUtf8(Stream, PAnsiChar(Phrase.Utf8),
Length(Phrase.Utf8), Options);
Exit;
end;
end;
end;
Stream.Seek(-BOMSize, soFromCurrent);
Result := StreamContainsPhraseAnsi(Stream, PAnsiChar(Phrase.Ansi),
Length(Phrase.Ansi), Options);
finally
Stream.Free;
end;
end;
Return to DELPHI AREA Projects
Users browsing this forum: No registered users and 2 guests