mcgill Posted August 8, 2006 Share Posted August 8, 2006 Good day, I would like to read into an INI file and search for a section then a keyword. Once keyword has been found I would like to delete every other line below this keyword in the ini file and save and close the file. Right now I am doing this with send key with file being opened and the user sees it happenning. How can I do it without the user seeing the file being opened in notepad, thanks $var = IniRead("C:\Program Files\Lotus\Notes\notes.ini", "Notes", "Timezone", "NotFound") Link to comment Share on other sites More sharing options...
BPBNA Posted August 8, 2006 Share Posted August 8, 2006 Try using _FileReadToArray then search each array element for the line, then overwrite the file and write the lines you want. Link to comment Share on other sites More sharing options...
Valik Posted August 8, 2006 Share Posted August 8, 2006 There is no sorting to an INI file. There is no guarantee that you won't accidentally delete data you wanted to keep if you search for a keyword and then delete the rest of the file. If you know which keys you need to delete, delete them and only them. Otherwise, if you know which keys you need to keep, you could delete all keys not matching them (This is dangerous, though). Just searching for a keyword and deleting all lines after that line could result in deleting almost the entire file. Link to comment Share on other sites More sharing options...
mcgill Posted August 8, 2006 Author Share Posted August 8, 2006 I understand it can be dangerous to delete certain lines in a ini file. All I need is a few lines(keys) after this section is found. The [Notes] section is the first and only section in the file. So After the Timezone text I want it to delete all the other lines in the ini file and save and close. This is a fix for lotus notes, thats why I want to do it. [Notes] KitType=1 Directory=C:\Program Files\lotus\notes\data InstallType=6 FaultRecovery_Build=Release 6.5.1 Timezone=6 Link to comment Share on other sites More sharing options...
Briegel Posted August 8, 2006 Share Posted August 8, 2006 I think it's easier to delete (or better rename) the old 'notes.ini' and then to write a new one. Link to comment Share on other sites More sharing options...
Valik Posted August 8, 2006 Share Posted August 8, 2006 I understand it can be dangerous to delete certain lines in a ini file. All I need is a few lines(keys) after this section is found. The [Notes] section is the first and only section in the file. So After the Timezone text I want it to delete all the other lines in the ini file and save and close. This is a fix for lotus notes, thats why I want to do it. [Notes] KitType=1 Directory=C:\Program Files\lotus\notes\data InstallType=6 FaultRecovery_Build=Release 6.5.1 Timezone=6What happens if your file appears like this? [Notes] Timezone=6 KitType=1 Directory=C:\Program Files\lotus\notes\data InstallType=6 FaultRecovery_Build=Release 6.5.1 Can you gurantee that the keys will be in the order you think 100% of the time? Are you really trying to say that you want to delete all the sections except for the Notes section? If that is what you are saying, see the IniReadSectionNames() function to get a list of all the section names. You can then iterate that list deleting all the sections except "Notes". Otherwise, you should look at IniReadSection() to enumerate the keys in a particular section and prune only the keys you don't need. Link to comment Share on other sites More sharing options...
Confuzzled Posted August 10, 2006 Share Posted August 10, 2006 Why bother with AutoIT - just do it in DOS - two lines! Echo [Notes] > newinifile.ini Type oldininfile.ini | Find "Timezone" >> newinifile.ini Note the single chevron (>) in the first line to create a new file (or overwrite an existing one), and a double chevron (>>) on the second line to append any lines that contain the word Timezone in the oldinifile.ini. The pipe (|) character just before the Find statement is a vertical bar, found above the backward slash (\) on my keyboard - it may be in a different place on yours. Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 10, 2006 Share Posted August 10, 2006 Why bother with AutoIT - just do it in DOS - two lines! Echo [Notes] > newinifile.ini Type oldininfile.ini | Find "Timezone" >> newinifile.ini Note the single chevron (>) in the first line to create a new file (or overwrite an existing one), and a double chevron (>>) on the second line to append any lines that contain the word Timezone in the oldinifile.ini. The pipe (|) character just before the Find statement is a vertical bar, found above the backward slash (\) on my keyboard - it may be in a different place on yours. That does not do what he wants, as it only copies lines containing "Timezone", all other lines drop in the bit bucket. To do this in CMD shell script still requires a For /F loop that appends each line until it sees "Timezone", then exits. Certainly doable, but not any easier than AutoIT, and still doesn't address the issue of being SURE that everything after "Timezone" really should be deleted. If you can make a list of offending keys, it would be much more reliable to just delete those keys directly. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now