Jump to content

Open latest ini file in notepad


Recommended Posts

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 by Mecano
Link to post
Share on other sites
  • Moderators

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: :bye:

#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
EndIf

Please ask if anything is unclear. :oops:

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 post
Share on other sites

@Melba23 thanx for your answer

this is really a wow effect :oops:

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 by Mecano
Link to post
Share on other sites
  • Moderators

Mecano,

Apologies for not replying sooner - I missed the thread update. :oops:

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. :bye:

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 post
Share on other sites
  • 2 weeks later...

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...