Shocker Posted October 7, 2018 Posted October 7, 2018 Hi there! Looking for a simple way to read and compare different values from different INI files. It could be 4 files (if exist) or fewer. The values should be same (normally). If they are equal, safe this value to a variable to write in a new INI. ;sections for file_a.ini, file_b.ini, file_c.ini and file_d.ini [SectionName1] Key=Value_A [SectionName2] Key=Value_B [SectionName3] Key=Value_C Any idea?
BrewManNH Posted October 7, 2018 Posted October 7, 2018 We need more information than this. What are you comparing from one INI file to another? Are you looking at section names, keys, values of those keys? What have you tried already? Do you have examples of the INI files you want compared and what should the output be in the new INI file using those INI files? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
careca Posted October 7, 2018 Posted October 7, 2018 From what i understand it's just one name from one section in each file, this should be simple enough, read all 4 values, and do a compare.. but yeah what did you try so far? Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe
caramen Posted October 8, 2018 Posted October 8, 2018 (edited) You can try somthing with FileExists ( "path" ) FileRead ( "filehandle/filename" [, count] ) IniRead ( "filename", "section", "key", "default" ) IniWrite ( "filename", "section", "key", "value" ) StringCompare ( "string1", "string2" [, casesense = 0] ) Edited October 8, 2018 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki
Shocker Posted October 8, 2018 Author Posted October 8, 2018 Thx for reply to all! Try some snippets with Array, but have no idea to compare Row's /Column's... Spoiler #include <Array.au3> Local $ini[4] = ["file_a.ini", "file_b.ini", "file_c.ini", "file_d.ini"] Local $aSection[3][2] = [["Drive", "path"], ["Language", "lang"], ["Servicekey", "active"]] Local $sArr[1][4] For $i = 0 To UBound($ini) - 1 If FileExists(@ScriptDir & "\" & $ini[$i]) Then For $j = 0 To UBound($aSection) - 1 $rINI = IniRead(@ScriptDir & "\" & $ini[$i], $aSection[$j][0], $aSection[$j][1], "") If Not @error Then If $rINI <> "" Then If $sArr[Ubound($sArr)-1][$j] <> '' Then ReDim $sArr[Ubound($sArr)+1][3] EndIf $sArr[Ubound($sArr)-1][$j] = $rINI EndIf EndIf Next EndIf Next _ArrayDisplay($sArr) Don't know if the right way? If all section values equal i want save to output.INI... file_a.ini file_b.ini file_c.ini file_d.ini
careca Posted October 8, 2018 Posted October 8, 2018 (edited) This was my solution, maybe there are better ones, but this is the best i could do. #include <Array.au3> FileDelete('temp.ini') Local $ini[4] = ["file_a.ini", "file_b.ini", "file_c.ini", "file_d.ini"] Local $aSection[3][2] = [["Drive", "path"], ["Language", "lang"], ["Servicekey", "active"]] For $i = 0 To UBound($ini, 1) - 1 ;ConsoleWrite($i & ' - $ini[?] - ' & $ini[$i] & @CRLF) If FileExists(@ScriptDir & "\" & $ini[$i]) Then For $j = 0 To UBound($aSection) - 1 $rINI = IniRead(@ScriptDir & "\" & $ini[$i], $aSection[$j][0], $aSection[$j][1], "") If Not @error Then ;ConsoleWrite('$rINI - ' & $rINI & @CRLF) If $rINI <> "" Then If IniRead('temp.ini', 'temp', $j, "") = '' Then IniWrite('temp.ini', 'temp', $j, $rINI) ConsoleWrite('First Write - '&$ini[$i]&' - '&$rINI&@CRLF) ElseIf IniRead('temp.ini', 'temp', $j, "") = $rINI Then ConsoleWrite('OK! Same value - '&$ini[$i]&' - '&$rINI&@CRLF) Else ConsoleWrite('Different! - '&$ini[$i]&' - '&$aSection[$j][0]&' - '& $aSection[$j][1]&' - '&$rINI&@CRLF) EndIf EndIf EndIf Next EndIf Next outputs to console, but there's a problem, if the first file to be read is the one different, the script will say all others are different, because it compares the other ones to the first one to be read. The good part is that if all you want to know is if any of them is different, it does the job. Edited October 8, 2018 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe
iamtheky Posted October 8, 2018 Posted October 8, 2018 On 10/7/2018 at 3:48 PM, Shocker said: If they are equal, safe this value to a variable Plenty of ways to determine if the files are the same take your pick above.... which parts do you want set as variables tho? the KV pairs? $arrA = FileReadToArray("file_a.ini") assign(stringsplit($arrA[1] , "=" , 2)[0] , stringsplit($arrA[1] , "=" , 2)[1]) assign(stringsplit($arrA[4] , "=" , 2)[0] , stringsplit($arrA[4] , "=" , 2)[1]) assign(stringsplit($arrA[7] , "=" , 2)[0] , stringsplit($arrA[7] , "=" , 2)[1]) msgbox(0, '' , Eval("path") & @CR & Eval("lang") & @CR & Eval("Active")) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
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