dash007 Posted August 10, 2005 Share Posted August 10, 2005 Hi, I saw this code in the forum from Larry but it is giving me errors on running it. Perhaps its because I am using the beta version which has quite a few changes as compared to the older version. The original code is: expandcollapse popup#include <GUIConstants.au3> #include <File.au3> #include <Array.au3> #include <String.au3> #include <INet.au3> ;#Include <FileSearch.au3> Dim $iMsgBoxAnswer Dim $LookFor $box=GUICreate("Hold *CONTROL KEY* to Select Muiltiple Files"); will create a dialog box that when displayed is centered $add=GUICtrlCreateButton ("Add", 164,360,75,25) $clear=GUICtrlCreateButton ("Clear", 64,360,75,25) $close=GUICtrlCreateButton ("Close", 264,360,75,25) $mylist=GUICtrlCreateListView ("Num#| File Name | Location ",15,15,370,300) GUICtrlSetLimit(-1,200); to limit horizontal scrolling ;GUICtrlSetData(-1,$MESSAGE) GUISetState(@SW_SHOW,$mylist) $iMsgBoxAnswer = MsgBox(48,"Searching","This may take a moment... Please wait...",3) ; Shows the filenames of all files in the current directory $LookFor = "*.bak" Dim $Files Dim $Dir="C:\"; specify the directory to search Dim $Filemask=$LookFor; specify the filemask ; Options are : ; 1 - looking in subfolders and not in current only ; 2 - show search status window ; 4 - cancel search by first match found $Files = _FileSearch($Dir, $Filemask, 1+2); set can be 1+2+4 If $Files[0] > 0 Then For $i = 1 to $Files[0] ;MsgBox(4096,"",$Files[$i]) GUISetState(@SW_SHOW,$mylist) GuiCtrlCreateListViewItem($Files[$i],$mylist) $count=ControlListView("Hold *CONTROL KEY* to Select Muiltiple Files","","SysListView321", "GetItemCount") $selected=ControlListView("Hold *CONTROL KEY* to Select Muiltiple Files","","SysListView321", "GetSelectedCount") GUICtrlCreateLabel("Found:" & $count,64,325,75,25) GUICtrlCreateLabel("Selected:" & $selected,264,325,75,25) GUISetState(@SW_SHOWMINNOACTIVE,$mylist) Next EndIf Func _FileSearch($StartDir, $FileToFind, $Options) ; $StartDir = specify the directory to search ; $FileToFind = specify the filemask ; $Options = 1 - looking in subfolders and not in current only ; 2 - show search status window ; 4 - cancel search by first match found Local $StartDir Local $FileToFind Local $Options Local $FileIndex Local $CurrDir Local $sCriteria Local $sBuffer Local $iH, $iH2 Local $sCS, $sCF, $sCF2, $sCP, $sFP Local $sOutPut = '' Local $aNull[1] ; An array is returned with the full path of all files found. The pos [0] keeps the number of elements. $sCP = StringLeft($StartDir, StringInStr($StartDir, '\', 0, -1)) If $sCP = '' Then $sCP = @WorkingDir & '\' $sCriteria = StringTrimLeft($FileToFind, StringInStr($FileToFind, '\', 0, -1)) If $sCriteria = '' Then $sCriteria = '*.*' ; To begin we seek in the starting path $sCS = FileFindFirstFile($sCP & $sCriteria) If BitAND($Options,2) = 2 then GUISetState(@SW_SHOWMINNOACTIVE,$mylist) $box2=SplashTextOn("Indexing ... Please wait ...", $sCP, 400, 130, -1, -1, 22, "Arial", 10) EndIf While $sCS <> - 1 $sCF = FileFindNextFile($sCS) If @error Then FileClose($sCS) ExitLoop EndIf If $sCF = '.' Or $sCF = '..' Then ContinueLoop $info=$sCF $sOutPut = $sOutPut & $sCP & $sCF & @LF $FileIndex = $FileIndex + 1 GUISetState(@SW_SHOW,$mylist) $count=ControlListView("Hold *CONTROL KEY* to Select Muiltiple Files","","SysListView321", "GetItemCount") $selected=ControlListView("Hold *CONTROL KEY* to Select Muiltiple Files","","SysListView321", "GetSelectedCount") GuiCtrlCreateListViewItem($FileIndex & "|" & $info & "|" & $currDir,$mylist) GUICtrlCreateLabel("Found:" & $count,64,320,75,25) GUICtrlCreateLabel("Selected:" & $selected,264,320,75,25) GUISetState(@SW_SHOWMINNOACTIVE,$mylist) If $FileIndex > 0 AND BitAND($Options,4) = 4 Then FileClose($sCS) ExitLoop EndIf Wend ; and after, if needed, in the rest of the folders. If $FileIndex > 0 AND BitAND($Options,4) = 4 Then Else If BitAND($Options,1) = 1 Then $sBuffer = @CR & $sCP & '*' & @LF; The buffer is set for keeping the given path plus a *. Do $sCS = StringTrimLeft(StringLeft($sBuffer, StringInStr($sBuffer, @LF, 0, 1) - 1),1); current search. $sCP = StringLeft($sCS, StringInStr($sCS, '\', 0, -1)); current search path. $iH = FileFindFirstFile($sCS) If BitAND($Options,2) = 2 then If StringLen($sCP) > 55 Then $CurrDir = StringLeft($sCP, 10) & " ... " & StringRight($sCP, 40) Else $CurrDir = $sCP EndIf ControlSetText("Indexing ... Please wait ...", _ "", _ "Static1", _ @CRLF & " Searching Files and Folders :" & _ @CRLF & $CurrDir & _ @CRLF & @CRLF & _ @CRLF & " Search Name" & @TAB & $sCriteria & _ @CRLF & " Matching Files Found" & @TAB & $FileIndex) EndIf While $iH <> - 1 $sCF = FileFindNextFile($iH) If @error Then FileClose($iH) ExitLoop EndIf If $sCF = '.' Or $sCF = '..' Then ContinueLoop If StringInStr(FileGetAttrib($sCP & $sCF), 'd') Then $sBuffer = @CR & $sCP & $sCF & '\*' & @LF & $sBuffer; Every folder found is added in the begin of buffer $sFP = $sCP & $sCF & '\'; for future searches $iH2 = FileFindFirstFile($sFP & $sCriteria); and checked with the criteria. While $iH2 <> - 1 $sCF2 = FileFindNextFile($iH2) If @error Then FileClose($iH2) ExitLoop EndIf If $sCF2 = '.' Or $sCF2 = '..' Then ContinueLoop $info=$scF2 $sOutPut = $sOutPut & $sFP & $sCF2 & @LF; Found items are put in the Output. $FileIndex = $FileIndex + 1 GUISetState(@SW_SHOW,$mylist) $count=ControlListView("Hold *CONTROL KEY* to Select Muiltiple Files","","SysListView321", "GetItemCount") $selected=ControlListView("Hold *CONTROL KEY* to Select Muiltiple Files","","SysListView321", "GetSelectedCount") GuiCtrlCreateListViewItem($FileIndex & "|" & $info & "|" & $currDir,$mylist) GUICtrlCreateLabel("Found:" & $FileIndex,64,320,75,25) GUICtrlCreateLabel("Selected:" & $selected,264,320,75,25) GUISetState(@SW_SHOWMINNOACTIVE,$mylist) If $FileIndex > 0 AND BitAND($Options,4) = 4 Then ExitLoop Wend EndIf Wend $sBuffer = StringReplace($sBuffer, @CR & $sCS & @LF, '') Until $sBuffer = '' Or $FileIndex > 0 AND BitAND($Options,4) = 4 EndIf EndIf If BitAND($Options,2) = 2 then SplashOff() EndIf If $sOutPut = '' Then $aNull[0] = 0 Return $aNull Else Return StringSplit(StringTrimRight($sOutPut, 1), @LF) EndIf GUISetState(@SW_SHOW,$mylist) EndFunc; ==>_FileSearch I get the error "Cannot redeclare a parameter inside a user function". I bypassed this issue by moving Local $StartDir Local $FileToFind Local $Options outside the function and the script seems to run, but after the search the gui stays active doing nothing but flickering (not searching anymore). I was hoping to get the output to a ListView as in above Larry's code. Can some please assist. Thanks in adv! Link to comment Share on other sites More sharing options...
dash007 Posted August 10, 2005 Author Share Posted August 10, 2005 I have noticed a possible bug with the new version of AutoIt3.exe. When using the new AutoIt3.exe from the latest beta, the ListView window in the above code does not come up. When using the older versions eg 3.1.1.18, I have no problems. Anyone else see this? If others see it too, then this request needs to be put in the Bug section of the forum I guess. Also how can I close the "search" message box after its done searching, it seems to stand and flicker! 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