Jump to content
Sign in to follow this  
cyberlogs

How to locate and overwrite in a text file ?

Recommended Posts

cyberlogs

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

Share this post


Link to post
Share on other sites
Melba23

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


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
cyberlogs

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

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  

×