Jump to content

Recommended Posts

Posted

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

  • Moderators
Posted

gazeranco,

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

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

 

Posted

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.

  • Moderators
Posted

gazeranco,

  Quote

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

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

 

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
Posted

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

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