ShareHolder Finder v0.9.3 is now released!!! Check Product Page for more details.


Wednesday, 23 March 2016

AutoIt - Insert data to a specific line in a file

Author Post Date Wednesday, 23 March 2016
User defined function _FileWriteToLine($sFilePath, $iLine, $sText [, $bOverWrite = False]) can be used for inserting 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.


#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")

;Insert a new line of data to line 3. The existing line will be shifted to next line.
_FileWriteToLine("c:\AutomationDevelopers\temp.csv", 3, "Sophia, 15")

Related Posts

Interesting? Share and Let Others Know.

Post a comment