Jump to content

Recommended Posts

Posted (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 by oemript
  • Developers
Posted

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.
  :)

Posted

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^)

 

  • Developers
Posted (edited)
  On 7/7/2019 at 8:34 AM, oemript said:

I would like to know on how to write string into file and overwrite any existing contents

Expand  

Seriously? So you simply want to override the existing file and you couldn't find the solution yourself when looking at 

  On 7/7/2019 at 8:34 AM, oemript said:

$hFileOpen = FileOpen($sFilePath, $FO_APPEND)

Expand  

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 by 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.
  :)

  • Moderators
Posted

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:

  Reveal hidden contents

 

  • Developers
Posted
  On 7/7/2019 at 8:44 AM, oemript said:

Thanks, to everyone very much for suggestions (^v^)

Expand  

I am being serious so do not see any reason why to tag my last post with a HAHA smiley! 

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.
  :)

  • Moderators
Posted (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 by JLogan3o13

"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!

  • Developers
Posted
  On 7/8/2019 at 3:00 AM, alienclone said:
$VAR = "hello world"
Run(@comspec & ' /k "echo '& $VAR &' > "D:\test.txt"', "", @SW_HIDE)

 

Expand  

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.
  :)

Posted
  On 7/8/2019 at 6:40 AM, Jos said:

Yea..  "All roads lead to Rome", but isn't the proper answer here. ;)

Expand  

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

  • Developers
Posted
  On 7/8/2019 at 6:59 AM, 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?

Expand  

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

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.
  :)

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
  • Recently Browsing   0 members

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