faustf Posted February 10, 2019 Share Posted February 10, 2019 (edited) 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 expandcollapse popup#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 February 10, 2019 by Melba23 Renamed thread as bug was in keyboard-chair interface - not AutoIt Link to comment Share on other sites More sharing options...
user4157124 Posted February 10, 2019 Share Posted February 10, 2019 Documentation (FileWrite() function) explicitly states to avoid this ("Do not mix filehandles and filenames"). AUERLO (AutoIt error logger) Link to comment Share on other sites More sharing options...
Nine Posted February 10, 2019 Share Posted February 10, 2019 You cannot mix the two : file with by handle and by name Because any file function using name will open, do its thing and close it. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
faustf Posted February 10, 2019 Author Share Posted February 10, 2019 i think is much better use always handle , thankz again JLogan3o13 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now