0x00
//有的文件中间有#00 此时Tstringlist等都要出错 #00->$20(#32)
//NoEOF('cxz.txt', 'q.txt', false);
function NoEOF(source_file_name: string; target_file_name: string; Rm_Src: boolean = False; CR: Char = #$00): string;
const
SWAP_NAME = 'D2U_';
var
swap_char: char;
s_stream, t_stream: TMemoryStream;
begin
s_stream := TMemoryStream.Create;
t_stream := TMemoryStream.Create;
try
s_stream.LoadFromFile(source_file_name);
s_stream.Position := 0;
while (s_stream.Position < s_stream.Size) do
begin
s_stream.ReadBuffer(swap_char, sizeof(swap_char));
if (swap_char = CR) then swap_char := #32;
t_stream.WriteBuffer(swap_char, sizeof(swap_char));
end; //end of while
finally
if (Rm_Src) then
begin
Deletefile(PChar(source_file_name));
result := ExtractFilePath(target_file_name) + ExtractFileName(source_file_name);
t_stream.SaveToFile(result);
end //end of if( If_Rm_Source )
else
begin
if (source_file_name <> target_file_name) then
result := target_file_name
else
result := ExtractFilePath(target_file_name) +
SWAP_NAME + ExtractFileName(target_file_name);
t_stream.SaveToFile(result);
end; //end of else
s_stream.Free;
t_stream.Free;
end; //end of finally
end;