Sign in to follow this  
Followers 0
YoannMorl

Compare Date in an Array and display lines found

16 posts in this topic

#1 ·  Posted (edited)

Hi,

I have an array filled with data from some ini files.

A section of each ini files contain a key named "AU" and containing a date like "2012/12/14".

Some files does not contain any value for "AU".

I need to the date from each file with the date of today and store in a file each line of the array if the date of today is before the date in the file.

This is what i've done for now :

$aIni_List = _FileListToArray(@ScriptDir & "DB", "*.ini", 1)

$aIni_Content = IniReadSection(@ScriptDir & "DB" & $aIni_List[1], "INFOS")

Global $aResults[$aIni_List[0] + 1][$aIni_Content[0][0]]

For $i = 1 To $aIni_Content[0][0]
$aResults[0][$i - 1] = $aIni_Content[$i][0]
Next

For $i = 1 To $aIni_List[0]
$aIni_Content = IniReadSection(@ScriptDir & "DB" & $aIni_List[$i], "INFOS")
For $j = 1 To $aIni_Content[0][0]
$aResults[$i][$j - 1] = $aIni_Content[$j][1]
Next
Next

I don't know how to do ? Could you help me please ?

Regards.

Edited by YoannMorl

Share this post


Link to post
Share on other sites



YoannMorl,

Do you have access to the original ini files? Do you have data from multiple ini files in this array, or is it from just the one? :huh:

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

#3 ·  Posted (edited)

With the script above, i have in the array all data from all ini files.

I can access to all ini files

Edited by YoannMorl

Share this post


Link to post
Share on other sites

YoannMorl,

I see you have now posted some code - always a good idea. ;)

More questions - as your explanation is none too clear. What do you mean by?

I need to the date from each file with the date of today

And if you find an "AU" date that is later than today's date, what do you mean by?

store in a file each line of the array

Perhaps if you post an example of an ini file and explain which lines are affected it would help. :)

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

Sorry for my bad english. I'm french ^^

Each ini files contains a section called "INFOS"

Each section on all files contain a key called "AU" with a value (or not) written like that : "2012/12/01"

I need to do a report of each file with the date contained in "AU" is prior the today date.

Ini files :

[iNFOS]

Key1=xxx

Key2=xxx

AU=2012/12/01

Share this post


Link to post
Share on other sites

YoannMorl,

This should get you started: :)

#include <File.au3>
#include <Date.au3>

; Get the list of ini files
$aIni_List = _FileListToArray(@ScriptDir, "*.ini", 1)

For $i = 1 To $aIni_List[0]

    ; See if a date value exists
    $sIni_Date = IniRead(@ScriptDir & "" & $aIni_List[$i], "INFOS", "AU", "Error")

    ConsoleWrite($sIni_Date & @CRLF)

    If $sIni_Date = "Error" Then

        ; Code for the case that there is no AU key/value pair <<<<<<<<<<<<<<<<<<

    Else

        $iDateDiff = _DateDiff("D", $sIni_Date, _NowCalc())
        If $iDateDiff > 0 Then

            ; Code for the case that AU date is before today <<<<<<<<<<<<<<<<<<

        Else

            ; Code for the case that AU date is today or after <<<<<<<<<<<<<<<<<<

        EndIf

    EndIf

Next

M23

P.S. Si j'ai mal compris, envoie-moi un PM en francais. ;)


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

#7 ·  Posted (edited)

Merci.

Voilà ce que j'ai pu faire :

Func _Retard()

; Get the list of ini files
$aIni_List = _FileListToArray(@ScriptDir & "DB", "*.ini", 1)

For $i = 1 To $aIni_List[0]

; See if a date value exists
$sIni_Date = IniRead(@ScriptDir & "DB" & $aIni_List[$i], "INFOS", "AU", "Error")

ConsoleWrite($sIni_Date & @CRLF)

If $sIni_Date = "Error" Then
$RetardStatus = "0"
Else
     $iDateDiff = _DateDiff("D", $sIni_Date, _NowCalc())
     If $iDateDiff > 0 Then
$RetardStatus = "1"
     Else
$RetardStatus = "2"
     EndIf

EndIf

Next

If $RetardStatus = "0" Then
MsgBox(0,"Debug","Toutes les ressources sont disponibles.")
ElseIf $RetardStatus = "1" Then
MsgBox(0,"Debug","Pas de ressources en retard")
ElseIf $RetardStatus = "2" Then
MsgBox(0,"Debug","Une ou plusieurs ressources sont en retard")
Else
MsgBox(0,"Debug","Erreur")
EndIf

EndFunc

How i can do to store data from the current ini file (in error) in a file ?

in fact, store each value from keys of the ini file corresponding to $RetardStatus = "2"

Edited by YoannMorl

Share this post


Link to post
Share on other sites

YoannMorl,

I said send me a PM in french - not to post in that language. We only use English in the forum. ;)

As to only getting notified about specific folders, take a look at this:

#include <Array.au3>
#include <File.au3>
#include <Date.au3>

_Retard()

Func _Retard()

    ; Create an array to hold the files that meet the criterion
    Local $aRetard[1] = [0]
    Local $RetardStatus = 0

    ; Get the list of ini files
    $aIni_List = _FileListToArray(@ScriptDir, "*.ini", 1)

    For $i = 1 To $aIni_List[0]

        ; See if a date value exists
        $sIni_Date = IniRead(@ScriptDir & "" & $aIni_List[$i], "INFOS", "AU", "Error")

        If $sIni_Date = "Error" Then
            ; Leave $RetardStatus unchanged
        Else
            ; Increase $RetardStatus
            $RetardStatus += 1
            ; Check the date
            $iDateDiff = _DateDiff("D", $sIni_Date, _NowCalc())
            If $iDateDiff > 0 Then
                ; Add the file to the array
                $aRetard[0] += 1
                ReDim $aRetard[$aRetard[0] + 1]
                $aRetard[$aRetard[0]] = $aIni_List[$i]
            EndIf
        EndIf

    Next

    Switch $RetardStatus
        Case 0
            MsgBox(0, "Debug", "Toutes les ressources sont disponibles.")
        Case Else
            Switch $aRetard[0]
                Case 0
                    MsgBox(0, "Debug", "Pas de ressources en retard")
                Case Else
                    MsgBox(0, "Debug", "Une ou plusieurs ressources sont en retard")
                    _ArrayDisplay($aRetard)
            EndSwitch
    EndSwitch

EndFunc   ;==>_Retard

Now you get notified about out-of-date files with a nice array showing their names. ;)

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

#9 ·  Posted (edited)

Yep ^^

That's exactly what i need ^^

The _ArrayDisplay gave me a list of ini files.

Is there a way to display value of keys for these ini files like "GRE", "NOM", "PRENOM", and "AU" in this array ?

I've tried with IniRead but without success.

For information, the final project is a tool for managing ressources reservation.

Edited by YoannMorl

Share this post


Link to post
Share on other sites

YoannMorl,

You need to change the code where you add the filename to the array. The array will need to be 2D so there is room for the additional data and you can fill these extra elements by using IniRead in the same way as you obtain the date. :)

Give it a go yourself - you know where to find me if you get stuck. ;)

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

#11 ·  Posted (edited)

Ok 'ill try something and let you see.

Thanks.

i've done that, but only 1 line is added to RETARD.TXT, nothing more

Func _Retard()

; Create an array to hold the files that meet the criterion
Local $aRetard[1] = [0]
Local $RetardStatus = 0

; Get the list of ini files
$aIni_List = _FileListToArray(@ScriptDir & "DB", "*.ini", 1)

For $i = 1 To $aIni_List[0]

; See if a date value exists
$sIni_Date = IniRead(@ScriptDir & "DB" & $aIni_List[$i], "INFOS", "AU", "Error")

If $sIni_Date = "Error" Then
; Leave $RetardStatus unchanged
Else
; Increase $RetardStatus
$RetardStatus += 1
; Check the date
$iDateDiff = _DateDiff("D", $sIni_Date, _NowCalc())
If $iDateDiff > 0 Then
; Add the file to the array
$aRetard[0] += 1
ReDim $aRetard[$aRetard[0] + 1]
$aRetard[$aRetard[0]] = $aIni_List[$i]

$RetardGRE = IniRead(@ScriptDir & "DB" & $aIni_List[$i],"INFOS","GRE","ERROR")
$RetardNOM = IniRead(@ScriptDir & "DB" & $aIni_List[$i],"INFOS","NOM","ERROR")
$RetardPRE = IniRead(@ScriptDir & "DB" & $aIni_List[$i],"INFOS","PRENOM","ERROR")
$RetardDAT = IniRead(@ScriptDir & "DB" & $aIni_List[$i],"INFOS","AU","ERROR")

FileDelete(@ScriptDir & "RETARD.TXT")
FileWriteLine(@ScriptDir & "RETARD.TXT","" & $RetardGRE & " - " & $RetardNOM & " " & $RetardPRE & " - " & $RetardDAT & "")

EndIf
EndIf

Next

Switch $RetardStatus
Case 0
MsgBox(0, "Debug", "Toutes les ressources sont disponibles.")
Case Else
Switch $aRetard[0]
Case 0
MsgBox(0, "Debug", "Pas de ressources en retard")
Case Else
MsgBox(0, "Debug", "Une ou plusieurs ressources sont en retard")
;~ _ArrayDisplay($aRetard)
ShellExecute(@ScriptDir & "RETARD.TXT")
EndSwitch
EndSwitch

EndFunc ;==>_Retard
Edited by YoannMorl

Share this post


Link to post
Share on other sites

YoannMorl,

Spot the difference: ;)

#include <Array.au3>
#include <File.au3>
#include <Date.au3>

_Retard()

Func _Retard()

    ; Create an array to hold the files that meet the criterion
    Local $aRetard[1] = [0]
    Local $RetardStatus = 0

    ; Get the list of ini files
    $aIni_List = _FileListToArray(@ScriptDir, "*.ini", 1)

    ; Delete an existing file
    FileDelete(@ScriptDir & "RETARD.TXT")

    For $i = 1 To $aIni_List[0]

        ; See if a date value exists
        $sIni_Date = IniRead(@ScriptDir & "" & $aIni_List[$i], "INFOS", "AU", "Error")

        If $sIni_Date = "Error" Then
            ; Leave $RetardStatus unchanged
        Else
            ; Increase $RetardStatus
            $RetardStatus += 1
            ; Check the date
            $iDateDiff = _DateDiff("D", $sIni_Date, _NowCalc())
            If $iDateDiff > 0 Then
                ; Add the file to the array
                $aRetard[0] += 1
                ReDim $aRetard[$aRetard[0] + 1]
                $aRetard[$aRetard[0]] = $aIni_List[$i]

                $RetardGRE = IniRead(@ScriptDir & "" & $aIni_List[$i], "INFOS", "GRE", "ERROR")
                $RetardNOM = IniRead(@ScriptDir & "" & $aIni_List[$i], "INFOS", "NOM", "ERROR")
                $RetardPRE = IniRead(@ScriptDir & "" & $aIni_List[$i], "INFOS", "PRENOM", "ERROR")
                $RetardDAT = $sIni_Date

                ; Add the data to the file
                FileWriteLine(@ScriptDir & "RETARD.TXT", "" & $RetardGRE & " - " & $RetardNOM & " " & $RetardPRE & " - " & $RetardDAT & "")

            EndIf
        EndIf

    Next

    Switch $RetardStatus
        Case 0
            MsgBox(0, "Debug", "Toutes les ressources sont disponibles.")
        Case Else
            Switch $aRetard[0]
                Case 0
                    MsgBox(0, "Debug", "Pas de ressources en retard")
                Case Else
                    MsgBox(0, "Debug", "Une ou plusieurs ressources sont en retard")
                    ShellExecute(@ScriptDir & "RETARD.TXT")
            EndSwitch
    EndSwitch

EndFunc   ;==>_Retard

Answer:

Delete the file

before the loop. :)

Good to go? :)

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

Are you serious ?

I've done this mistake ?

Sorry :( ^^

Share this post


Link to post
Share on other sites

YoannMorl,

Are you serious ?

I've done this mistake ?

Just look at the code you posted! :D

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

I think i can continue now. Thank you for your help and your patience.

Share this post


Link to post
Share on other sites

YoannMorl,

Il n'y a pas de quoi. :)

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

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  
Followers 0