Mega Code Archive

 
Categories / Delphi / Files
 

Add Line into the end of a file

Title: Add Line into the end of a file Question: You want to write a line in a large file, use this procedure to do this. Answer: procedure AddLine_InFile(sLine: String; const FilePath: string); { sLine = String that go to the end of file. FilePath = FullPath of the file. } var pLog: Textfile; begin try AssignFile(pLog, FilePath); // Assing a Path to TextFile. if not FileExists(FilePath) then // Check Existence. Rewrite(pLog, FilePath); // If not Make a new file. Append(pLog); // Set Current line as the end. WriteLn(pLog, sLine); // Write sLine if file. finally CloseFile(pLog); // Close the file. end; end;