#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
; Assign the file path to a variable
Local $sFilePath = "C:\AutomationDevelopers\temp.txt"
;Open the file temp.txt in overwrite mode. If the folder C:\AutomationDevelopers does not exist, it will be created.
Local $hFileOpen = FileOpen($sFilePath, $FO_OVERWRITE + $FO_CREATEPATH)
;Display a message box in case of any errors.
If $hFileOpen = -1 Then
MsgBox($MB_SYSTEMMODAL, "", "An error occurred when opening the file.")
EndIf
;Write a line of data to file by passing the previously opened file handle. Newline (@CRLF) will be automatically added.
FileWriteLine($hFileOpen, "This is the first line.")
FileWriteLine($hFileOpen, "This is the second line.")
;Close the handle returned by FileOpen.
FileClose($hFileOpen)
#include <MsgBoxConstants.au3>
; Assign the file path to a variable
Local $sFilePath = "C:\AutomationDevelopers\temp.txt"
;Open the file temp.txt in overwrite mode. If the folder C:\AutomationDevelopers does not exist, it will be created.
Local $hFileOpen = FileOpen($sFilePath, $FO_OVERWRITE + $FO_CREATEPATH)
;Display a message box in case of any errors.
If $hFileOpen = -1 Then
MsgBox($MB_SYSTEMMODAL, "", "An error occurred when opening the file.")
EndIf
;Write a line of data to file by passing the previously opened file handle. Newline (@CRLF) will be automatically added.
FileWriteLine($hFileOpen, "This is the first line.")
FileWriteLine($hFileOpen, "This is the second line.")
;Close the handle returned by FileOpen.
FileClose($hFileOpen)
FileWriteLine will write a text of line to end of file. If the text of line does NOT end in @CR or @LF, then a DOS linefeed (@CRLF) will be
automatically added. So that the next FileWriteLine operation will add text to next line.
FileWriteLine() returns 1 for Success and 0 for failures (if file not opened in writemode, file is read only, or file cannot otherwise be
written to).
- AutoIt - Write data to a file
- AutoIt - Write data to a specific line in a file (overwrite the existing line)
- AutoIt - Insert data to a specific line in a file
- AutoIt - Read data from a file
- AutoIt - Read a specific line of data from a file
- AutoIt - Read data from a file to an array
- AutoIt - Open a file for read/ write operations
Interesting? Share and Let Others Know.
Post a Comment