oemript Posted July 7, 2019 Share Posted July 7, 2019 (edited) Referring to following link, I would like to know on how to write string into file without append option, so the file should only contain "Line 4". Local Const $sFilePath = "D:\test.txt" Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND) ; 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") ; Close the handle returned by FileOpen. FileClose($hFileOpen) Does anyone have any suggestions? Thanks in advance for any suggestions https://www.autoitscript.com/autoit3/docs/functions/FileWrite.htm Edited July 7, 2019 by oemript JLogan3o13 1 Link to comment Share on other sites More sharing options...
Developers Jos Posted July 7, 2019 Developers Share Posted July 7, 2019 I do not understand the question looking at the example. Do you want to insert a record in an existing file in between existing other records? If so: Open the Helpfile and search for the existing solution, else define again what your question is. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
oemript Posted July 7, 2019 Author Share Posted July 7, 2019 Referring to FileWrite, there is no other option for selection, if I only want to write data into file without appending existing contents, by default it is using $FO_APPEND. $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If File D:\test.txt is already existed with contents, I would like to know on how to write string into file and overwrite any existing contents, so for this coding, FileWrite($hFileOpen, "Line 4") file should only contain "Line 4". Do you have any suggestions? Thank you very much for any suggestions (^v^) Link to comment Share on other sites More sharing options...
Developers Jos Posted July 7, 2019 Developers Share Posted July 7, 2019 (edited) 2 hours ago, oemript said: I would like to know on how to write string into file and overwrite any existing contents Seriously? So you simply want to override the existing file and you couldn't find the solution yourself when looking at 2 hours ago, oemript said: $hFileOpen = FileOpen($sFilePath, $FO_APPEND) Please learn to open the helpfile before posting questions as you have been around long enough to be able to solve stuff yourself. remember? : Jos Edited July 7, 2019 by Jos oemript 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 7, 2019 Moderators Share Posted July 7, 2019 oemript, And if you look in the Help file for FileOpen what flags can you see which you might use other than $FO_APPEND and which might do what you want? M23 oemript 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
oemript Posted July 7, 2019 Author Share Posted July 7, 2019 Thanks, to everyone very much for suggestions (^v^) Link to comment Share on other sites More sharing options...
Developers Jos Posted July 7, 2019 Developers Share Posted July 7, 2019 2 hours ago, oemript said: Thanks, to everyone very much for suggestions (^v^) I am being serious so do not see any reason why to tag my last post with a HAHA smiley! oemript 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
oemript Posted July 7, 2019 Author Share Posted July 7, 2019 I am deeply appreciate everyone kindness for sharing Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 7, 2019 Moderators Share Posted July 7, 2019 (edited) You are on notice @oemript, the entire community is becoming tired of your general laziness and wanting everyone to spoon feed common sense to you. The next one will result in a good long holiday from the forum. Edited July 7, 2019 by JLogan3o13 Earthshine and FrancescoDiMuro 1 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
alienclone Posted July 8, 2019 Share Posted July 8, 2019 (edited) $VAR = "hello world" Run(@comspec & ' /k "echo '& $VAR &' > "D:\test.txt"', "", @SW_HIDE) Edited July 8, 2019 by Jos If @error Then MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!") EndIf "Yeah yeah yeah patience, how long will that take?" -Ed Gruberman REAL search results | SciTE4AutoIt3 Editor Full Version Link to comment Share on other sites More sharing options...
oemript Posted July 8, 2019 Author Share Posted July 8, 2019 (edited) Thanks, to everyone very much for suggestions (^v^) Edited July 8, 2019 by oemript Link to comment Share on other sites More sharing options...
Developers Jos Posted July 8, 2019 Developers Share Posted July 8, 2019 3 hours ago, alienclone said: $VAR = "hello world" Run(@comspec & ' /k "echo '& $VAR &' > "D:\test.txt"', "", @SW_HIDE) Yea.. "All roads lead to Rome", but isn't the proper answer here. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
alienclone Posted July 8, 2019 Share Posted July 8, 2019 16 minutes ago, Jos said: Yea.. "All roads lead to Rome", but isn't the proper answer here. he asked for any suggestions, my code writes string to file without append which looked to me to be the OP's end goal, how is it not proper? If @error Then MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!") EndIf "Yeah yeah yeah patience, how long will that take?" -Ed Gruberman REAL search results | SciTE4AutoIt3 Editor Full Version Link to comment Share on other sites More sharing options...
Developers Jos Posted July 8, 2019 Developers Share Posted July 8, 2019 2 hours ago, alienclone said: he asked for any suggestions, my code writes string to file without append which looked to me to be the OP's end goal, how is it not proper? Well, I would think doing a FIleOpen() with the $FO_OVERWRITE property is a more appropriate answer, don't you think? ... but as said : "roads.... Rome".... Jos FrancescoDiMuro 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. 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