Sign in to follow this  
Followers 0
gazeranco

Write to file from file

8 posts in this topic

I have a script which overwrites some text in a file. Curently, I edit the code to change the text it writes.

However, I would like to save a text file that the user can edit, then run the exe and it writes to the file from the user.txt file.

Can anyone provide an example of this?

Thanks

Share this post


Link to post
Share on other sites



gazeranco,

What code have you tried that has not worked correctly? :oops:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

None tbh, I can't find a way of doing it... I am a nooby to this stuff and thumbling my way through with the help examples :oops:

I was looking in the help for like a WriteFromFile command but I couldn't find one.

Share this post


Link to post
Share on other sites

hmm I guess I need to read it into memory somehow and then write it from there?

Share this post


Link to post
Share on other sites

gazeranco,

I guess I need to read it into memory

Quite probably - and what function do you think might be useful there? Hint - it begins with "File". :oops:

There is even a function to read the file into an array with each line in a separate element - you will find that a couple if places lower in the Help file index - which sounds as if it might be even more useful. :bye:

Top Tip: If you were to post the script you are currently using to show you have made some effort rather than expecting us to write code for you, you might get more than just hints. :doh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

yay i did it :oops: (well technically, the help file did it... but i was there...)

While 1
        Local $line = FileReadLine($filer)
            If @error = -1 Then ExitLoop
        FileWriteLine($file, $line)
    WEnd
Edited by gazeranco

Share this post


Link to post
Share on other sites

So far, I believe you are looking for Find and Replace method. If so, heres it:

$TextFileName = "TextFile.txt"
$FindText = "dog"
$ReplaceText = FileRead("userfile.txt")

$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents,$FindText,$ReplaceText)
FileDelete($TextFileName)
FileWrite($TextFileName,$FileContents)

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Share this post


Link to post
Share on other sites

gazeranco,

I this related to this topic

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0