Mecano Posted March 29, 2012 Share Posted March 29, 2012 (edited) Hallo AutoIt lovers I have a piece of software that makes temp ini files in the TempDir, ( sometimes there are 20 tmp.ini files) the AutoIt script has to open the latest made ini file in Notepad. I came up with this one: Global $Search, $sLastFound = "", $sFound = "" $Search = FileFindFirstFile(@TempDir & "*.ini") If $Search = -1 Then MsgBox(16, "Error", "No tmp.ini files found in " & @TempDir) Exit EndIf While 1 $sFound = FileFindNextFile($Search) If @error Then ExitLoop $sLastFound = $sFound WEnd ShellExecute("notepad.exe", @TempDir & "" & $sLastFound) Is there any control that i know that really the latest ini is opened in notepad? Edited March 29, 2012 by Mecano Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 29, 2012 Moderators Share Posted March 29, 2012 Mecano,It is much easier to use the _FileListToArray function than to fiddle around with the FileFindFirst/NextFile pair. Then you can loop through the returned files very easily like this: #include <File.au3> ; Get a list of .ini files $aList = _FileListToArray(@TempDir, "*.ini", 1) ; Are there any files? If @error then MsgBox(0, "Error", "No ini files found") Else ; Set a dummy date $sLatest = 19991231000000 $iIndex = 0 ; Loop through the found files For $i = 1 To $aList[0] ; Get the date $sDTG = FileGetTime(@TempDir & "" & $aList[$i], 0, 1) If @error Then MsgBox(0, "Error", "Cannot read the date for " & $aList[$i]) Else ; Compare to latest so far If $sDTG > $sLatest Then ; Set new latest $sLatest = $sDTG $iIndex = $i EndIf EndIf Next ; Did we find something? If $iIndex Then MsgBox(0, "Latest", $aList[$iIndex]) Else MsgBox(0, "Error", "Nothing found") EndIf EndIfPlease ask if anything is unclear. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Mecano Posted March 29, 2012 Author Share Posted March 29, 2012 (edited) @Melba23 thanx for your answer this is really a wow effect is this the good way to open the found ini file in Notepad? ; Did we find something? If $iIndex Then ;MsgBox(0, "Latest", $aList[$iIndex]) ShellExecute("notepad.exe", @TempDir & "" & $aList[$iIndex]) Else MsgBox(0, "Error", "Nothing found") EndIf thanks in advance Edited March 29, 2012 by Mecano Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 30, 2012 Moderators Share Posted March 30, 2012 Mecano,Apologies for not replying sooner - I missed the thread update. If you want to use ShellExecute then you use the filename as the first parameter and let Windows open it in the editor associated with .ini files:ShellExecute(@TempDir & "" & $aList[$iIndex], @TempDir & "")Alternatively you can use Run to force the editor of your choice:Run('notepad.exe "' & @TempDir & '' & $aList[$iIndex] & '"')Note the mix of single and double quotes - I have put the filename in double quotes in case you have spaces in the path. If you do not you can remove them. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jdelaney Posted March 30, 2012 Share Posted March 30, 2012 Why open it at all, why not just read it, and make any changes, or store any settings needed? IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Mecano Posted April 8, 2012 Author Share Posted April 8, 2012 @Melba23 Noprob, Thank you for this clear explanation ... me happy @jdelaney They are tmp.ini just to check, whats written and than close This is just fine Thank you all 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