|
本帖最后由 m765555 于 2011-5-26 10:00 编辑
想写个带进度条的垃圾清理工具,因个人能力有限,需要各位兄弟指点一二,以下代码运行时要满足三个文件夹下都有文件才能正常运行,而且默认的是清理三个文件夹,能力有限,无法写出指定清理那个文件夹的代码,代码如下:
程序测试图片:#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#Include <Array.au3>
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\桌面\Form1.kxf
$Form1 = GUICreate("垃圾清理工具", 456, 304, 292, 215)
GUISetIcon("E:\系统类\mycom.ico", -1)
$Label1 = GUICtrlCreateLabel(" 清理当前用户临时文件夹", 104, 48, 139, 17)
$Label2 = GUICtrlCreateLabel("清理windows下临时文件夹", 104, 80, 141, 17)
$Label3 = GUICtrlCreateLabel("清理windows预读文件夹", 104, 120, 129, 17)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 72, 48, 17, 17, -1, $WS_EX_CLIENTEDGE)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 72, 80, 17, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_BOTTOM), $WS_EX_CLIENTEDGE)
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox2", 72, 116, 17, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_BOTTOM), $WS_EX_CLIENTEDGE)
$Progress1 = GUICtrlCreateProgress(24, 232, 409, 17)
$Button2 = GUICtrlCreateButton("开始清理", 200, 160, 81, 25)
$Button1 = GUICtrlCreateButton("全选", 288, 160, 81, 25)
$Label4 = GUICtrlCreateLabel("运行状态:", 24, 200, 55, 17)
$Label5 = GUICtrlCreateLabel("", 88, 200, 232, 17)
$Group1 = GUICtrlCreateGroup("请选择操作项目", 48, 16, 337, 137, BitOR($GUI_SS_DEFAULT_GROUP,$BS_CENTER))
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
qx()
Case $Button2
dq()
EndSwitch
WEnd
Func qx()
GUICtrlSetState($Checkbox1,$GUI_CHECKED)
GUICtrlSetState($Checkbox2,$GUI_CHECKED)
GUICtrlSetState($Checkbox3,$GUI_CHECKED)
EndFunc
Func dq()
If $Checkbox1 Then
$m1=@UserProfileDir&""&"Local Settings\Temp"
;$ml="C:\123"
$lb1=_FileListToArray($m1)
;$size=DirGetSize($ml)
;_ArrayDisplay($lb,"$lb")
;MsgBox(0,"目录大小",$size/1000000&"M")
$lb1=_ArrayMemeberInsert($lb1,$m1&"");返回精数组1完整路径
EndIf
If $Checkbox2 Then
$m2="c:\windows\Temp"
;$ml="C:\123"
$lb2=_FileListToArray($m2)
;$size=DirGetSize($ml)
;_ArrayDisplay($lb,"$lb")
;MsgBox(0,"目录大小",$size/1000000&"M")
$lb2=_ArrayMemeberInsert($lb2,$m2&"");返回精数组1完整路径
EndIf
If $Checkbox3 Then
$m3="C:\WINDOWS\Prefetch"
;$ml="C:\123"
$lb3=_FileListToArray($m3)
;$size=DirGetSize($ml)
;_ArrayDisplay($lb,"$lb")
;MsgBox(0,"目录大小",$size/1000000&"M")
$lb3=_ArrayMemeberInsert($lb3,$m3&"");返回精数组1完整路径
EndIf
;_ArrayDisplay($lb1,1)
;_ArrayDisplay($lb2,2)
;_ArrayDisplay($lb3,3)
;_ArrayDelete($lb1,0)
;_ArrayDelete($lb2,0)
;_ArrayDelete($lb3,0)
_ArrayConcatenate($lb1,$lb2)
_ArrayConcatenate($lb1,$lb3)
;_ArrayDisplay($lb1,"0") ;显示所有数据
$lb1[0]=$lb1[0]+$lb2[0]+$lb3[0]
;_ArrayDelete($lb1,0)
;MsgBox(0,0,$lb1[0])
;#cs
Dim $at
For $i=0 To $lb1[0]
;MsgBox(0,"",($lb[$i]))
$at=FileGetAttrib($lb1[$i])
If $at="R" Or $at="H" Then
FileSetAttrib($lb1[$i],"-RH",1)
EndIf
If FileGetAttrib($lb1[$i])="D" Then
DirRemove($lb1[$i],1)
EndIf
FileDelete($lb1[$i])
GUICtrlSetData($Label5,"正在清理"&$lb1[$i])
GUICtrlSetData($Progress1,($i/$lb1[0])*100)
If GUICtrlRead($Progress1)=100 Then
GUICtrlSetData($Label5,"清理已完成,谢谢使用!")
EndIf
If $i<0 Then ExitLoop
Next
;#ce
EndFunc
;定义一个能让数组返回完整路径的函数_ArrayMemeberInsert
; 数组元素插入字符串 要插入的数组 插入的字符串 方向 0为左 1为右 从第几个元素开始。
Func _ArrayMemeberInsert($__Array="",$__InsertString="",$__Direction=0,$__StartMember=1)
If $__Array="" Then Return
For $i=$__StartMember To UBound($__Array)-1 Step 1
Switch $__Direction
Case 0
$__Array[$i]=$__InsertString&$__Array[$i]
Case 1
$__Array[$i]=$__Array[$i]&$__InsertString
Case Else
ExitLoop
EndSwitch
Next
Return $__Array
EndFunc
上面代码是前两天琢磨的,为了改进,我现在弄得以下这种形式,可是依然无法解决选择文件夹的功能,如果解决了选择文件夹的功能,但又不能解决进度条的问题,二者我只能解决一个问题,请各位指点一下,有兴趣的朋友来研究下,代码改进如下:#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#Include <Array.au3>
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\桌面\Form1.kxf
$Form1 = GUICreate("垃圾清理工具", 456, 304, 292, 215)
GUISetIcon("E:\系统类\mycom.ico", -1)
Dim $Checkbox[4],$m[4],$lb[4]
$Label1 = GUICtrlCreateLabel(" 清理当前用户临时文件夹", 104, 48, 139, 17)
$Label2 = GUICtrlCreateLabel("清理windows下临时文件夹", 104, 80, 141, 17)
$Label3 = GUICtrlCreateLabel("清理windows预读文件夹", 104, 120, 129, 17)
$Checkbox[1] = GUICtrlCreateCheckbox("Checkbox1", 72, 48, 17, 17, -1, $WS_EX_CLIENTEDGE)
$Checkbox[2] = GUICtrlCreateCheckbox("Checkbox2", 72, 80, 17, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_BOTTOM), $WS_EX_CLIENTEDGE)
$Checkbox[3] = GUICtrlCreateCheckbox("Checkbox2", 72, 116, 17, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_BOTTOM), $WS_EX_CLIENTEDGE)
$m[1]=@UserProfileDir&""&"Local Settings\Temp"
$m[2]="c:\windows\Temp"
$m[3]="C:\WINDOWS\Prefetch"
$Progress1 = GUICtrlCreateProgress(24, 232, 409, 17)
$Button2 = GUICtrlCreateButton("开始清理", 200, 160, 81, 25)
$Button1 = GUICtrlCreateButton("全选", 288, 160, 81, 25)
$Label4 = GUICtrlCreateLabel("运行状态:", 24, 200, 55, 17)
$Label5 = GUICtrlCreateLabel("", 88, 200, 250, 20)
GUICtrlSetColor(-1, 0xff0000)
$Group1 = GUICtrlCreateGroup("请选择操作项目", 48, 16, 337, 137, BitOR($GUI_SS_DEFAULT_GROUP,$BS_CENTER))
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
qx()
Case $Button2
dq()
EndSwitch
WEnd
Func qx()
GUICtrlSetState($Checkbox[1],$GUI_CHECKED)
GUICtrlSetState($Checkbox[2],$GUI_CHECKED)
GUICtrlSetState($Checkbox[3],$GUI_CHECKED)
EndFunc
Func dq()
If GUICtrlRead($Checkbox[1])<>$GUI_CHECKED And GUICtrlRead($Checkbox[2])<>$GUI_CHECKED And GUICtrlRead($Checkbox[3])<>$GUI_CHECKED Then
GUISetState(@SW_DISABLE)
MsgBox(16,"提示","请选择要操作的项目",1)
GUISetState(@SW_ENABLE)
EndIf
Dim $ds=0
For $i=1 To 3
If GUICtrlRead($Checkbox[$i])=$GUI_CHECKED Then
$lb[$i]=_FileListToArray($i)
_ArrayDisplay($lb[$i],"0")
$lb[$i]=_ArrayMemeberInsert($lb[$i],$m[$i]&"");返回精数组1完整路径
EndIf
Next
;_ArrayConcatenate($lb1,$lb[2])
;_ArrayConcatenate($lb1,$lb[3])
;_ArrayDisplay($lb1,"0") ;显示所有数据
;$lb1[0]=$lb1[0]+$lb2[0]+$lb3[0]
Dim $at
For $i=1 To $lb[$i-1]
;MsgBox(0,"",($lb[$i]))
$at=FileGetAttrib($lb[$i])
If $at="R" Or $at="H" Then
FileSetAttrib($lb[$i],"-RH",1)
EndIf
If FileGetAttrib($lb[$i])="D" Then
DirRemove($lb[$i],1)
EndIf
FileDelete($lb[$i])
GUICtrlSetData($Label5,"正在清理"&$lb[$i])
GUICtrlSetData($Progress1,($i/$lb[0])*100)
If GUICtrlRead($Progress1)=100 Then
GUICtrlSetData($Label5,"清理已完成,谢谢使用!")
EndIf
If $i<0 Then ExitLoop
Next
EndFunc
;定义一个能让数组返回完整路径的函数_ArrayMemeberInsert
; 数组元素插入字符串 要插入的数组 插入的字符串 方向 0为左 1为右 从第几个元素开始。
Func _ArrayMemeberInsert($__Array="",$__InsertString="",$__Direction=0,$__StartMember=1)
If $__Array="" Then Return
For $i=$__StartMember To UBound($__Array)-1 Step 1
Switch $__Direction
Case 0
$__Array[$i]=$__InsertString&$__Array[$i]
Case 1
$__Array[$i]=$__Array[$i]&$__InsertString
Case Else
ExitLoop
EndSwitch
Next
Return $__Array
EndFunc
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入
×
|