Jump to content

FileWrite Problem?


faustf
 Share

Recommended Posts

hi guys , how much is correct   write  filewrite (path file )  or is much better   filewrite (handle of file ) ?  , i ask this  because i have a  big script , and  in this  i used  filewrite (path file ) , is always run but    today i dnotknow  why  not work ,return me error , i just fix  it  with  second  case   filewrite (handle of file )

i try to reproduce bug  with little script  , but  work , therfore i  do this questions

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

Example()

Func Example()
    ; Create a constant variable in Local scope of the filepath that will be read/written to.
    Local Const $sFilePath = _WinAPI_GetTempFileName(@ScriptDir)

    ; Create a temporary file to write data to.
    If Not FileWrite($sFilePath, "Start of the FileWrite example, line 1. " & @CRLF) Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
        Return False
    EndIf

    ; Open the file for writing (append to the end of a file) and store the handle to a variable.
    Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
        Return False
    EndIf

    ; Write data to the file using the handle returned by FileOpen.
    FileWrite($hFileOpen, "Line 2")
    FileWrite($hFileOpen, "This is still line 2 as a new line wasn't appended to the last FileWrite call." & @CRLF)
    FileWrite($hFileOpen, "Line 3" & @CRLF)
    FileWrite($hFileOpen, "Line 4")

    FileWrite(@ScriptDir &"\folder2\text.txt", "Line 4")

    ; Close the handle returned by FileOpen.
    FileClose($hFileOpen)

    ; Display the contents of the file passing the filepath to FileRead instead of a handle returned by FileOpen.
    MsgBox($MB_SYSTEMMODAL, "", "Contents of the file:" & @CRLF & FileRead($sFilePath))

    ; Delete the temporary file.
    ;FileDelete($sFilePath)
EndFunc   ;==>Example

 

Edited by Melba23
Renamed thread as bug was in keyboard-chair interface - not AutoIt
Link to comment
Share on other sites

  • Melba23 changed the title to FileWrite Problem?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...