本帖最后由 setqsetq 于 2010-5-31 17:30 编辑
为什么按开始键不开始搜索.
按完开始再按停止,有时多点几次就可以了?为什么啊?..
怎样修改呢??
#include <WindowsConstants.au3>
#include <GuiConstants.au3>
GUICreate("MyGUI", 450 ,150, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$Progress_1 = GUICtrlCreateProgress(10, 10, 370, 20)
$Label1 = GUICtrlCreateLabel("扫描目录", 24, 80, 52, 17)
$Label2 = GUICtrlCreateLabel("", 24, 112, 276, 17)
$Button_2 = GUICtrlCreateButton("开始", 10, 40, 60, 30)
$Button_3 = GUICtrlCreateButton("停止", 80, 40, 60, 30)
$Button_4 = GUICtrlCreateButton("退出", 150, 40, 70, 30)
Opt("GUIOnEventMode", 1)
Dim $start = -1, $ostart
Global $pause = True
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
GUICtrlSetOnEvent($Button_2, "gui")
GUICtrlSetOnEvent($Button_3, "gui")
GUICtrlSetOnEvent($Button_4, "gui")
While 1
If $pause = False Then
$start = 0
$Drive = DriveGetDrive("FIXED")
For $i = 1 To $Drive[0]
If $pause = False Then
_filelist($Drive[$i])
EndIf
Next
EndIf
WEnd
Func gui()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE, $Button_4
$pause = True
Exit
Case $Button_2
$pause = False
Case $Button_3
$pause = True
EndSwitch
EndFunc ;==>gui
Func _filelist($searchdir)
$search = FileFindFirstFile($searchdir & "\*.*") ;;;;查指定目录下的文件
If $search = -1 Then Return -1 ;;;;如果找不到,返回值 -1
While 1
If $pause = False Then ExitLoop
$file = FileFindNextFile($search) ;;;查找下一个文件
If @error Then ;;;如果找不到文件
FileClose($search) ;;;则关闭此句柄
Return ;;;返回
ElseIf $file = "." Or $file = ".." Then ;;如果找到的文件名为.或..则ContinueLoop
ContinueLoop ;;;在某些版本的AU3里面可以不需要上行和这行。
ElseIf StringInStr(FileGetAttrib($searchdir & "\" & $file), "D") Then ;;如果找到的是一个文件夹,则
_filelist($searchdir & "\" & $file) ;;递归调用filelist函数,并传参数 "$searchdir & "\" & $file"
GUICtrlSetData($Label2, $searchdir & "\" & $file) ;显示搜索文件夹
GUICtrlSetData($Progress_1, $start)
$start = $start + 0.1
EndIf ;;;$file为查找到的文件夹名称,上一行意思就是进入此文件夹继续查找文件.如此循环
ConsoleWrite($searchdir & "\" & $file & @CRLF)
;~ If StringInStr($file, 'QQ.exe') Then MsgBox(0, 0, $searchdir & "\" & $file & @CRLF)
WEnd
EndFunc ;==>_filelist
|