Jump to content

How to locate and overwrite in a text file ?


Recommended Posts

Hey autoit users

im kinda stuck in my project at the moment, cause i simply just cant figure out how to solve the following problem....

I have a GUI with some checkbox's on and a button.

then i have a text file which look like this

-- a bunch of random code --
Encryption = True
Set Style = 3   //can be 1,2,3,4 & 5
Password = xxxx
-- a bunch of random code --

my question is now, how can i locate the string "Encryption = " and then overwrite the "True" with a "False"

i want it so that if i check the checkbox in my GUI and then press the button it should open the file, find the string Encryption and change it to True/false wether the checkbox is checked or not

Sorry for my poor english

just post here if you need more information :blink:

thanks in advance

CL

Link to comment
Share on other sites

  • Moderators

cyberlogs,

Welcome to the AutoIt forum. :blink:

One way to do what you asked:

- Use FileRead to read the contents of the file.

- Use StringReplace to replace your target string with the new one. I would replace the whole "Encryption = True/False" string.

- Open the file with FileOpen - using mode 2 to overwrite the exisitng version - then FileWrite the new contents and finally FileClose to tidy up. Do not forget that you will need to use the handle returned by FileOpen with FileWrite and FileClose. :P

- All done. ;)

have you looked at the Ini file commands? They might provide an easier way to save your values. :

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:

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

 

Link to comment
Share on other sites

cyberlogs,

Welcome to the AutoIt forum. :blink:

One way to do what you asked:

- Use FileRead to read the contents of the file.

- Use StringReplace to replace your target string with the new one. I would replace the whole "Encryption = True/False" string.

- Open the file with FileOpen - using mode 2 to overwrite the exisitng version - then FileWrite the new contents and finally FileClose to tidy up. Do not forget that you will need to use the handle returned by FileOpen with FileWrite and FileClose. :nuke:

- All done. ;)

have you looked at the Ini file commands? They might provide an easier way to save your values. :>

M23

Thanks for the warm welcome :P

as im pretty known in the ini i cant understand why i didnt thought of this, but anyway i got it working now :

thanks you very much, see you sometime in another topic :)

CL

Link to comment
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
 Share

  • Recently Browsing   0 members

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