LATEST UPDATES
ShareHolder Finder v0.9.3 is now released!!! Check Product Page for more details.
✉ info@automationdevelopers.com

ITS ALL ABOUT AUTOMATION

Wednesday, 23 March 2016

AutoIt - Write data to a specific line in a file (overwrite the existing line)


Author Post Date Wednesday, 23 March 2016
User defined function _FileWriteToLine($sFilePath, $iLine, $sText [, $bOverWrite = False]) can be used for writing data to a specific line. The OverWrite flag will decide on whether to overwrite the existing line or not. The default is False (No overwrite). The function is defined in the include file File.au3 and it is very useful when there is requirement for updating CSV files etc.

Example:

#include <File.au3>

; Assign the file path to a variable
Local $sFilePath = "C:\AutomationDevelopers\temp.csv"

;Write a set of lines for demonstration
FileWriteLine($sFilePath, "Name, Age")
FileWriteLine($sFilePath, "David, 12")
FileWriteLine($sFilePath, "Gloria, 14")
FileWriteLine($sFilePath, "Isaac, 13")

;Write data to line 3 by replacing the existing line
_FileWriteToLine("c:\AutomationDevelopers\temp.csv", 3, "Gloria - Replaced, 15", True)


Related Posts




Interesting? Share and Let Others Know.

Post a Comment