telmob Posted February 17, 2017 Share Posted February 17, 2017 (edited) Hi, I have multiple text files with multiple dates inside on every line 6 of each file, with format 30/02/2017. If i use the code below, i can check for the dates in each file: #Include <File.au3> $path = FileOpenDialog("SELECT",@ScriptDir,"All (*.txt)",1) Dim $LINE _FileReadToArray($path,$LINE) Local $ShowDate = StringLeft($LINE[6],10) MsgBox(0,"LINE 6",$ShowDate) I can also display which files have specific dates: expandcollapse popup#include <Array.au3> #include <Constants.au3> #include <MsgBoxConstants.au3> #include <GUIConstants.au3> #include <File.au3> #include <StringConstants.au3> #include <GuiListView.au3> #include <GUIConstantsEx.au3> GUICreate("listview items", 646, 430, 100, 200, -1) GUISetState(@SW_SHOW) MakeList() Func MakeList() Local $aArray = _FindInFile('20/02/2017', @ScriptDir, '*.txt') $listviewD = GUICtrlCreateListView(" Data Confere", 488, 5, 156, 390) For $INDEX = 1 To $aArray[0] $sFileName = StringRegExpReplace($aArray[$INDEX], "^.*\\|\.*$", "") $sFileNameTrim = StringTrimRight($sFileName,4) GUICtrlCreateListViewItem($sFileNameTrim, $listviewD) Next $Label2 = GUICtrlCreateLabel(_GUICtrlListView_GetItemCount($listviewD), 488, 400, 36, 17) EndFunc ;==>MakeList While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _FindInFile($sSearch, $sFilePath, $sMask = '*', $fRecursive = True, $fLiteral = Default, $fCaseSensitive = Default, $fDetail = Default) Local $sCaseSensitive = $fCaseSensitive ? '' : '/i', $sDetail = $fDetail ? '/n' : '/m', $sRecursive = ($fRecursive Or $fRecursive = Default) ? '/s' : '' If $fLiteral Then $sSearch = ' /c:' & $sSearch EndIf If $sMask = Default Then $sMask = '*' EndIf $sFilePath = StringRegExpReplace($sFilePath, '[\\/]+$', '') & '\' Local Const $aMask = StringSplit($sMask, ';') Local $iPID = 0, $sOutput = '' For $i = 1 To $aMask[0] $iPID = Run(@ComSpec & ' /c ' & 'findstr ' & $sCaseSensitive & ' ' & $sDetail & ' ' & $sRecursive & ' "' & $sSearch & '" "' & $sFilePath & $aMask[$i] & '"', @SystemDir, @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($iPID) $sOutput &= StdoutRead($iPID) Next Return StringSplit(StringStripWS(StringStripCR($sOutput), BitOR($STR_STRIPLEADING, $STR_STRIPTRAILING)), @LF) EndFunc ;==>_FindInFile But i can't display files that have dates, in line 6, different (lower) from the date i chose. So if i search for a specific date, i can find it and display it, but i need to get the filenames of all the files that have dates different from the date i select and display it in a listview, and i can't find a way to do that. Something like 'Not 20/02/2017' in the function below would be way to easy...: Func MakeList() Local $aArray = _FindInFile(Not '20/02/2017', @ScriptDir, '*.txt') $listviewD = GUICtrlCreateListView(" Data Confere", 488, 5, 156, 390) For $INDEX = 1 To $aArray[0] $sFileName = StringRegExpReplace($aArray[$INDEX], "^.*\\|\.*$", "") $sFileNameTrim = StringTrimRight($sFileName,4) GUICtrlCreateListViewItem($sFileNameTrim, $listviewD) Next $Label2 = GUICtrlCreateLabel(_GUICtrlListView_GetItemCount($listviewD), 488, 400, 36, 17) EndFunc ;==>MakeList Any ideas anyone? I admit, i'm completely lost. Edited February 17, 2017 by telmob Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 17, 2017 Moderators Share Posted February 17, 2017 telmob, I would do something like this: #include <GUIConstantsEx.au3> #include <File.au3> #include <GuiListView.au3> $aFiles = _FileListToArray(@ScriptDir, "*.txt", $FLTA_FILES, True) $hGUI = GUICreate("Test", 500, 500) $cLV = GUICtrlCreateListView("", 10, 10, 400, 200) _GUICtrlListView_AddColumn($cLV, "Filename", 190) _GUICtrlListView_AddColumn($cLV, "Date", 190) ; Loop through each file and get date 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 ; Add data to ListView GUICtrlCreateListViewItem($aFiles[$i] & "|" & $sDate, $cLV) Next GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd 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...
telmob Posted February 17, 2017 Author Share Posted February 17, 2017 (edited) Thanks for the quick reply Melba23. I took a while to understand the code, but i got it. But i still need to show only the files with dates lower than a specific date, for example lower than 20/02/2017. The script is currently showing all the files and dates. I think an easy way to solve this would be to compare the two columns and display only the items that are lower from a specific date. I have two text files with the date 20/02/2017 and one file with a different date, for example. Edited February 17, 2017 by telmob Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 17, 2017 Moderators Share Posted February 17, 2017 telmob, Once you have the date from within each file, use _DateDiff to check it against the specific date and only display the file/date if it is earlier. You will have to get the dates into the correct format to be compared, but that is trivial. 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...
telmob Posted February 17, 2017 Author Share Posted February 17, 2017 Nice! This time i got it working. Thank you again for your time and help. 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 $original = $sDate $new = StringRegExpReplace($original, "\A(\d*)/(\d*)/(\d*)","$3/$2/$1") $iDateCalc = _DateDiff('D', $new, "2017/02/10") $sLastDate = $iDateCalc <> "0" $sFileNameTrim1 = StringRegExpReplace($aFiles[$i], "^.*\\|\.txt", "") ; Add data to ListView If $iDateCalc <> "0" Then GUICtrlCreateListViewItem($sFileNameTrim1, $cLV) Next 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