telmob Posted February 20, 2017 Share Posted February 20, 2017 I have several (1000+) text files in the directory test\ with contents like the following: text1 20/01/2016 text text1 The date is always on the same line. I need to find, in all the files, the one that has the newest date. I know i need to change the date format, that is no problem, i can change it. But i have no idea in how to find the newest date. Is there a function reference that can do that? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 20, 2017 Moderators Share Posted February 20, 2017 telmob, Just as we did in your last thread, use _DateDiff on each file checking to see if this file is earlier than the earliest one we have found so far. 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...
mikell Posted February 20, 2017 Share Posted February 20, 2017 Maybe a faster way than using _DateDiff : format the dates "20/01/2016" to numbers "20160120" and then look for the highest one ? Link to comment Share on other sites More sharing options...
telmob Posted February 21, 2017 Author Share Posted February 21, 2017 Thank you both. I was wondering how i could find the highest (date) value without having something to compare with (like i did in my previous post). You guys rock! Time to put my brains to work. Link to comment Share on other sites More sharing options...
telmob Posted February 21, 2017 Author Share Posted February 21, 2017 Ok, i know i'm doing something wrong here: For $i = 1 To $aFiles[0] $aLines = FileReadToArray($aFiles[$i]) $sDate = StringLeft($aLines[5], 10) ; Note element 5 = line 6 because array is 0-based $new = StringRegExpReplace($sDate, "\A(\d*)/(\d*)/(\d*)","$3$2$1"); converts date to number format (20170210 for ex.) $iDateCalc = _DateDiff('D', $new, $new_new) $sLastDate = $iDateCalc < "0" $sFileNameTrim1 = StringRegExpReplace($aFiles[$i], "^.*\\|\.txt", "") ; Add data to ListView If $iDateCalc <> "0" Then GUICtrlCreateListViewItem($sFileNameTrim1, $Diferenca) Next _ArrayDisplay($new);not displaying anything. Not an array? msgbox("","",_ArrayMax($new, 1, 1));nope. I'm going nuts... Link to comment Share on other sites More sharing options...
mikell Posted February 21, 2017 Share Posted February 21, 2017 Sure. You don't compare the same things any more. The code must be adapted to number comparison Local $highest, $myfile = $aFiles[1] For $i = 1 To $aFiles[0] $aLines = FileReadToArray($aFiles[$i]) $sDate = StringLeft($aLines[5], 10) ; Note element 5 = line 6 because array is 0-based $new = StringRegExpReplace($sDate, "\A(\d*)/(\d*)/(\d*)","$3$2$1"); converts date to number format (20170210 for ex.) If $new > $highest Then $highest = $new $myfile = $aFiles[$i] EndIf Next msgbox(0,"", $myfile & " (" & $highest & ")" ) Link to comment Share on other sites More sharing options...
telmob Posted February 21, 2017 Author Share Posted February 21, 2017 LOL! And i was looking for something more complicated.... Thank you so much Mikell! 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