spac3m0nk3y Posted July 13, 2007 Share Posted July 13, 2007 (edited) What I'm trying to do is read a list of files. Each filename contains the date and a specific person's initials. I only want to display, in a listview, the names of people that actually have files in a "Todays Work" folder. So, if I have a list of files in "Todays Work" like so: filename123 07-13-2007 JQP.doc filename456 07-12-2007 JQP.doc filename789 0713-2007 FBD.doc and I have an ini file like so: [names] Public, John Q.=JQP Public, Jane S.=JSP Doe, Fred B.=FBD then I only want "Public, John Q." and "Doe, Fred B." to display in the listview. I was thinking of reading the list of files in the "Todays Work" folder into an array and then somehow doing a string search compare on that array using the values I read from my ini file. Is there a better way to do this, or will I just have to strengthen my string-fu skills? Thanks. Edited July 13, 2007 by spac3m0nk3y Website: http://www.mayniac.org Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 13, 2007 Moderators Share Posted July 13, 2007 What I'm trying to do is read a list of files. Each filename contains the date and a specific person's initials. I only want to display, in a listview, the names of people that actually have files in a "Todays Work" folder. So, if I have a list of files in "Todays Work" like so: filename123 07-13-2007 JQP.doc filename456 07-12-2007 JQP.doc filename789 0713-2007 FBD.doc and I have an ini file like so: [names] Public, John Q.=JQP Public, Jane S.=JSP Doe, Fred B.=FBD then I only want "Public, John Q." and "Doe, Fred B." to display in the listview. I was thinking of reading the list of files in the "Todays Work" folder into an array and then somehow doing a string search compare on that array using the values I read from my ini file. Is there a better way to do this, or will I just have to strengthen my string-fu skills? Thanks.IniReadSection ... [N][0] << 0 contains the key... [1] is the value... all you need is the key, so it's already in an array for you Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
spac3m0nk3y Posted July 13, 2007 Author Share Posted July 13, 2007 IniReadSection ... [N][0] << 0 contains the key... [1] is the value... all you need is the key, so it's already in an array for you Yeah, I've gotten that and I can list *all* the names in my listview, but I don't want all the names, just the ones that have files in the "todays work" folder. Website: http://www.mayniac.org Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 13, 2007 Moderators Share Posted July 13, 2007 (edited) Yeah, I've gotten that and I can list *all* the names in my listview, but I don't want all the names, just the ones that have files in the "todays work" folder.So do IniReadSection Todays ... IniReadSection All ... Do a loop with All, and If All = Today store it in a string and load your listview from that string.Edit:I meant instead of IniReadSection today's to put todays into an array like you had suggestd... Edited July 13, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
spac3m0nk3y Posted July 13, 2007 Author Share Posted July 13, 2007 This is what I have so far. It will list the files in my "Todays Work" folder in a listview. expandcollapse popup#include <GUIConstants.au3> #include <array.au3> #include <file.au3> #include <GuiListView.au3> #NoTrayIcon Opt("GUIOnEventMode",1) #region Global Constants ; Message Handlers Global Const $WM_NOTIFY = 0x004E ; ListView Events Global Const $LVN_FIRST = -100 Global Const $LVN_BEGINDRAG = ($LVN_FIRST - 9) Global Const $NM_FIRST = 0 Global Const $NM_LAST = (-99) Global Const $NM_OUTOFMEMORY = ($NM_FIRST - 1) Global Const $NM_CLICK = ($NM_FIRST - 2) Global Const $NM_DBLCLK = ($NM_FIRST - 3) ; ListView Messages Global Const $LVM_HITTEST = ($LVM_FIRST + 18) Global Const $LVM_CREATEDRAGIMAGE = ($LVM_FIRST + 33) Global Const $LVM_SETITEM = ($LVM_FIRST + 6) ; Mask Constants Global Const $LVIF_IMAGE = 0x0002 Global Const $LVIF_PARAM = 0x0004 Global Const $LVIF_INDENT = 0x0010 Global Const $LVIF_NORECOMPUTE = 0x0800 Global $Inuse = False, $sendfrm, $SendLst, $SendDir #endregion End Global variables $iBase = 1 $iUnique = 1 #Region ============================= Variables $todayswork = "C:\Todays Work\" #endregion #Region ### START Koda GUI section ### $SendFrm = GUICreate("Send Documents", 350, 301, -1, -1, -1, -1) $Group1 = GUICtrlCreateGroup("Send", 8, 8, 313, 281) $SendLst = GUICtrlCreateListView("Dir", 16, 32, 217, 249, $LVS_SORTASCENDING) $SendBtn = GUICtrlCreateButton("Send", 240, 48, 73, 25, 0) ;GUICtrlSetOnEvent($SendBtn, "SendDocs") $ExitBtn = GUICtrlCreateButton("Exit", 240, 224, 73, 25, 0) GUICtrlSetOnEvent($ExitBtn, "OnExit") GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUISetState(@SW_SHOW) GUICtrlSetData($SendLst, '');Empty the control $lstProviders $SendDir = _FileListToArrayEx($todayswork, '*.*') $aNames = IniReadSection("names.ini", "Names") For $i = 1 To $SendDir[0] GUICtrlCreateListViewItem($SendDir[$i] & Chr(124), $SendLst) Next _GUICtrlListViewSetColumnWidth ($SendLst, 0, $LVSCW_AUTOSIZE) GUISetState(@SW_SHOW) ; Display the GUI GUISetOnEvent($GUI_EVENT_CLOSE,"OnExit") #EndRegion ### END Koda GUI section ### While 1 Sleep (1000) WEnd Func OnExit() Exit EndFunc ;------------------------ _FileListToArrayEx Function -----------------------; Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '') If Not FileExists($sPath) Then Return SetError(1, 1, '') If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*' If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0 If $sExclude = -1 Or $sExclude = Default Then $sExclude = '' Local $aBadChar[6] = ['', '/', ':', '>', '<', '|'] For $iCC = 0 To 5 If StringInStr($sFilter, $aBadChar[$iCC]) Or _ StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '') Next If StringStripWS($sFilter, 8) = '' Then Return SetError(2, 2, '') If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '') If Not StringInStr($sFilter, ';') Then $sFilter &= ';' Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead For $iCC = 1 To $aSplit[0] If StringStripWS($aSplit[$iCC], 8) = '' Then ContinueLoop If StringLeft($aSplit[$iCC], 1) = '.' And _ UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC] Local $iPid = Run(@ComSpec & ' /c ' & 'dir "' & $sPath & '' & $aSplit[$iCC] _ & '" /b /o-e /od', '', @SW_HIDE, 6) While 1 $sRead &= StdoutRead($iPid) If @error Then ExitLoop WEnd Next If StringStripWS($sRead, 8) = '' Then SetError(4, 4, '') Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($sRead), 1), @LF) Local $sHold For $iCC = 1 To $aFSplit[0] If $sExclude And StringLeft($aFSplit[$iCC], _ StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop Switch $iFlag Case 0 $sHold &= $aFSplit[$iCC] & Chr(1) Case 1 If StringInStr(FileGetAttrib($sPath & '' & $aFSplit[$iCC]), 'd') Then ContinueLoop $sHold &= $aFSplit[$iCC] & Chr(1) Case 2 If Not StringInStr(FileGetAttrib($sPath & '' & $aFSplit[$iCC]), 'd') Then ContinueLoop $sHold &= $aFSplit[$iCC] & Chr(1) EndSwitch Next If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1)) Return SetError(4, 4, '') EndFunc Website: http://www.mayniac.org Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 13, 2007 Moderators Share Posted July 13, 2007 This is what I have so far. It will list the files in my "Todays Work" folder in a listview.And? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
spac3m0nk3y Posted July 13, 2007 Author Share Posted July 13, 2007 And?How do I search for the user's initials in the filelist and correlate that with the value in the ini file to only display the user's names that have files? Website: http://www.mayniac.org Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 13, 2007 Moderators Share Posted July 13, 2007 (edited) How do I search for the user's initials in the filelist and correlate that with the value in the ini file to only display the user's names that have files?I'll tell you ... you guys and not showing any attempt on your own for problems you run into is really getting old, I'm starting to miss my sabbatical ... $SendDir = _FileListToArrayEx($todayswork, '*.*') $aNames = IniReadSection("names.ini", "Names") $aLVLoad = _CompareToIni($SendDir, $aNames) If IsArray($aLVLoad) = 0 Then MsgBox(16, 'Error', 'Error with $SendDir or $aNames') ;Exit EndIf Func _CompareToIni(ByRef $avArray, ByRef $aIni) Local $sHold = '', $aSRE For $iCC = 1 To UBound($avArray) - 1 $aSRE = StringRegExp($avArray[$iCC], 'filname\d+ \d+-\d+-\d+ (.*?)\.doc', 1) If IsArray($aSRE) Then For $xCC = 1 To UBound($aIni) - 1 If $aIni[$xCC][1] = $aSRE[0] Then $sHold &= $aIni[$xCC][0] & Chr(1) ExitLoop EndIf EndIf EndIf Next If $sHold Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1)) Return SetError(1, 0, '') EndIf Edit: Looking at my code, I got ahead of my self on the 3rd line of the function. Edited July 13, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
spac3m0nk3y Posted July 13, 2007 Author Share Posted July 13, 2007 I'll tell you ... you guys and not showing any attempt on your own for problems you run into is really getting old, I'm starting to miss my sabbatical ... $SendDir = _FileListToArrayEx($todayswork, '*.*') $aNames = IniReadSection("names.ini", "Names") $aLVLoad = _CompareToIni($SendDir, $aNames) If IsArray($aLVLoad) = 0 Then MsgBox(16, 'Error', 'Error with $SendDir or $aNames') ;Exit EndIf Func _CompareToIni(ByRef $avArray, ByRef $aIni) Local $sHold = '', $aSRE For $iCC = 1 To UBound($avArray) - 1 $aSRE = StringRegExp($avArray[$iCC], 'filname\d+ \d+-\d+-\d+ (.*?)\.doc', 1) If IsArray($aSRE) Then For $xCC = 1 To UBound($aIni) - 1 If $aIni[$xCC][1] = $aSRE[0] Then $sHold &= $aIni[$xCC][0] & Chr(1) ExitLoop EndIf EndIf EndIf Next If $sHold Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1)) Return SetError(1, 0, '') EndIf Edit: Looking at my code, I got ahead of my self on the 3rd line of the function. Thank you. Website: http://www.mayniac.org 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